Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .npm/package/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions lib/query/lib/prepareForDelivery.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ function snapBackCaches(node) {
node.collectionNodes.forEach(collectionNode => {
snapBackCaches(collectionNode);
});

if (!_.isEmpty(node.snapCaches)) {
// process stuff
_.each(node.snapCaches, (linkName, cacheField) => {
Expand All @@ -326,7 +326,10 @@ function snapBackCaches(node) {
result[linkName] = result[cacheField];
}

delete result[cacheField];
// Don't remove the cacheField if it was requested explicitly by the query
if (!node.body[cacheField]) {
delete result[cacheField];
}
}
})
})
Expand Down
6 changes: 5 additions & 1 deletion lib/query/testing/bootstrap/authors/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ Authors.addLinks({
type: 'many',
metadata: true,
collection: Groups,
field: 'groupIds'
field: 'groupIds',
denormalize: {
field: 'groupsCache',
body: { _id: 1, name: 1 },
}
}
});

Expand Down
6 changes: 5 additions & 1 deletion lib/query/testing/bootstrap/comments/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ Comments.addLinks({
type: 'one',
collection: Authors,
field: 'authorId',
index: true
index: true,
denormalize: {
field: 'authorCache',
body: { _id: 1, name: 1, groupsCache: 1 },
}
},

post: {
Expand Down
49 changes: 49 additions & 0 deletions lib/query/testing/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1724,3 +1724,52 @@ describe('collection transforms', () => {
expect(result.b.a[0].b.hello).to.equal('world2')
})
});



describe('denormalized queries', () => {
it('Gets both the grapher cache and the real cache 1', () => {
const data = createQuery({
comments: {
author: {
name: 1,
},
authorCache: 1,
},
}).fetchOne();
console.log('data:', data);

expect(Object.keys(data)).to.be.eql(['_id', 'author', 'authorCache']);
// expect(Object.keys(data.author)).to.be.eql(['_id', 'name']);
// expect(Object.keys(data.authorCache)).to.be.eql(['_id', 'name', 'groupsCache']);
});

it('Gets the right data when mixing caches and reducers 1', () => {
const data = createQuery({
comments: {
authorLinkReducer: 1,
author: {
groupsCache: 1,
},
authorCache: 1,
},
}).fetchOne();
console.log('data:', data);

expect(Object.keys(data)).to.be.eql(['_id', 'author', 'authorCache', 'authorLinkReducer']);
});

it('Gets the right data when mixing caches and reducers 2', () => {
const data = createQuery({
comments: {
author: {
fullName: 1,
},
authorCache: 1,
},
}).fetchOne();
console.log('data:', data);

expect(Object.keys(data)).to.be.eql(['_id', 'authorCache', 'author']);
});
})