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:
committed by
Antonio Davi Macedo Coelho de Castro
parent
45dabbbcda
commit
4bffdce047
@@ -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 };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user