mirror of
https://github.com/vale981/grapher
synced 2025-03-04 17:11:38 -05:00
Merge pull request #319 from bhunjadi/recursive-fetch-update
Recursive fetch update
This commit is contained in:
commit
0d81e7e687
5 changed files with 64 additions and 4 deletions
|
@ -55,8 +55,12 @@ function fetch(node, parentObject, fetchOptions = {}) {
|
|||
* - pass node.results to accessor above and find with sift
|
||||
*/
|
||||
|
||||
const currentIds = _.pluck(collectionNode.results, '_id');
|
||||
collectionNode.results.push(...collectionNodeResults.filter(res => !_.contains(currentIds, res._id)));
|
||||
collectionNode.results.push(...collectionNodeResults);
|
||||
|
||||
// this was not working because all references must be replaced in snapBackCaches, not only the ones that are
|
||||
// found first
|
||||
// const currentIds = _.pluck(collectionNode.results, '_id');
|
||||
// collectionNode.results.push(...collectionNodeResults.filter(res => !_.contains(currentIds, res._id)));
|
||||
})
|
||||
});
|
||||
|
||||
|
|
|
@ -15,4 +15,5 @@ if (Meteor.isServer) {
|
|||
Posts.expose();
|
||||
Groups.expose();
|
||||
Authors.expose();
|
||||
Users.expose();
|
||||
}
|
||||
|
|
|
@ -41,6 +41,17 @@ Posts.addLinks({
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
tagsCached: {
|
||||
collection: Tags,
|
||||
type: 'many',
|
||||
field: 'tagIds',
|
||||
denormalize: {
|
||||
field: 'tagsCache',
|
||||
body: {
|
||||
name: 1
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -10,5 +10,16 @@ Users.addLinks({
|
|||
collection: Users,
|
||||
field: 'subordinateIds',
|
||||
type: 'many'
|
||||
}
|
||||
},
|
||||
friendsCached: {
|
||||
collection: Users,
|
||||
field: 'friendIds',
|
||||
type: 'many',
|
||||
denormalize: {
|
||||
field: 'friendsCache',
|
||||
body: {
|
||||
name: 1
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
|
@ -271,7 +271,40 @@ describe('Query Client Tests', function () {
|
|||
assert.isFunction(clone.setParams({}).fetchOne);
|
||||
});
|
||||
|
||||
it('Should work with denormalized fields in the many links', async () => {
|
||||
const query = createQuery({
|
||||
users: {
|
||||
$filters: {
|
||||
name: {$regex: 'User - (2|3)'}
|
||||
},
|
||||
friends: {
|
||||
name: 1,
|
||||
friendsCached: {
|
||||
name: 1
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const handle = query.subscribe();
|
||||
await waitForHandleToBeReady(handle);
|
||||
|
||||
const users = query.fetch();
|
||||
|
||||
assert.equal(users.length, 2);
|
||||
users.forEach(user => {
|
||||
user.friends.forEach(friend => {
|
||||
// each friend should have defined friendsCached
|
||||
assert.isArray(friend.friendsCached);
|
||||
// db cache field should be removed
|
||||
assert.isUndefined(friend.friendCache);
|
||||
|
||||
friend.friendsCached.forEach(cache => assert.isString(cache.name));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Should work securely with reactive queries and linked exposures', function () {
|
||||
|
||||
})
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue