mirror of
https://github.com/vale981/grapher
synced 2025-03-04 17:11:38 -05:00
Updated recursiveFetch to work with denormalized fields in array links
This commit is contained in:
parent
7635337c37
commit
64252de628
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
|
* - pass node.results to accessor above and find with sift
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const currentIds = _.pluck(collectionNode.results, '_id');
|
collectionNode.results.push(...collectionNodeResults);
|
||||||
collectionNode.results.push(...collectionNodeResults.filter(res => !_.contains(currentIds, res._id)));
|
|
||||||
|
// 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();
|
Posts.expose();
|
||||||
Groups.expose();
|
Groups.expose();
|
||||||
Authors.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,
|
collection: Users,
|
||||||
field: 'subordinateIds',
|
field: 'subordinateIds',
|
||||||
type: 'many'
|
type: 'many'
|
||||||
}
|
},
|
||||||
|
friendsCached: {
|
||||||
|
collection: Users,
|
||||||
|
field: 'friendIds',
|
||||||
|
type: 'many',
|
||||||
|
denormalize: {
|
||||||
|
field: 'friendsCache',
|
||||||
|
body: {
|
||||||
|
name: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -270,7 +270,40 @@ describe('Query Client Tests', function () {
|
||||||
assert.isFunction(clone.setParams({}).fetchOne);
|
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 () {
|
it('Should work securely with reactive queries and linked exposures', function () {
|
||||||
|
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue