GraphQL: Inline Fragment on Array Fields (#5908)

* Inline Fragment Spec

* Inline Fragment on Arrays

* Fix Test

* Only select the root field

* Requested Changes

* Lazy Loaded ArrayResult
This commit is contained in:
Antoine Cormouls
2019-08-14 21:25:28 +02:00
committed by Antonio Davi Macedo Coelho de Castro
parent 45dabbbcda
commit 4bffdce047
7 changed files with 247 additions and 61 deletions

View File

@@ -12,3 +12,30 @@ export function toGraphQLError(error) {
}
return new ApolloError(message, code);
}
export const extractKeysAndInclude = selectedFields => {
selectedFields = selectedFields.filter(
field => !field.includes('__typename')
);
let keys = undefined;
let include = undefined;
if (selectedFields && selectedFields.length > 0) {
keys = selectedFields.join(',');
include = selectedFields
.reduce((fields, field) => {
fields = fields.slice();
let pointIndex = field.lastIndexOf('.');
while (pointIndex > 0) {
const lastField = field.slice(pointIndex + 1);
field = field.slice(0, pointIndex);
if (!fields.includes(field) && lastField !== 'objectId') {
fields.push(field);
}
pointIndex = field.lastIndexOf('.');
}
return fields;
}, [])
.join(',');
}
return { keys, include };
};