Skip to content

Commit

Permalink
fix issue with removeLinkStorages when specificaly querying the link …
Browse files Browse the repository at this point in the history
…fields
  • Loading branch information
vparpoil committed Oct 15, 2019
1 parent 6bb5075 commit 658bf1d
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions lib/query/lib/prepareForDelivery.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,30 @@ export function removeLinkStorages(node, sameLevelResults) {
const [root, ...nested] = collectionNode.linkStorageField.split('.');

const removeFromResult = (result, removeEmptyRoot = false) => {
if (isSingle) {
dot.pick(collectionNode.linkStorageField, result, true);
if (removeEmptyRoot && nested.length > 0 && _.isEmpty(result[root])) {
delete result[root];
}
}
else {
if (nested.length > 0) {
const arr = result[root] || [];
if (_.isArray(arr)) {
arr.forEach(obj => dot.pick(nested.join('.'), obj, true));
if (removeEmptyRoot && nested.length > 0 && arr.every(obj => _.isEmpty(obj))) {
delete result[root];
}
const parentBody = collectionNode.parent ? collectionNode.parent.body : {};
if (!(root in parentBody)) {
if (isSingle) {
dot.pick(collectionNode.linkStorageField, result, true);
if (removeEmptyRoot && nested.length > 0 && _.isEmpty(result[root])) {
delete result[root];
}
}
else {
delete result[collectionNode.linkStorageField];
if (nested.length > 0) {
const arr = result[root] || [];
if (_.isArray(arr)) {
arr.forEach(obj => dot.pick(nested.join('.'), obj, true));
if (removeEmptyRoot && nested.length > 0 && arr.every(obj => _.isEmpty(obj))) {
delete result[root];
}
}
}
else {
delete result[collectionNode.linkStorageField];
}
}
}

};

if (collectionNode.isVirtual) {
Expand Down

0 comments on commit 658bf1d

Please sign in to comment.