Fix fragments in nested relational sets

Fixes #4283
This commit is contained in:
rijkvanzanten
2021-04-14 12:12:32 -04:00
parent b2ff80cb74
commit 40ecd1ec37

View File

@@ -1139,16 +1139,26 @@ export class GraphQLService {
): readonly SelectionNode[] | null {
if (!selections) return null;
return flatten(
const result = flatten(
selections.map((selection) => {
// Fragments can contains fragments themselves. This allows for nested fragments
if (selection.kind === 'FragmentSpread') {
// Fragments can contains fragments themselves. This allows for nested fragments
return this.replaceFragmentsInSelections(fragments[selection.name.value].selectionSet.selections, fragments);
}
// Nested relational fields can also contain fragments
if (selection.kind === 'Field' && selection.selectionSet) {
selection.selectionSet.selections = this.replaceFragmentsInSelections(
selection.selectionSet.selections,
fragments
) as readonly SelectionNode[];
}
return selection;
})
).filter((s) => s) as SelectionNode[];
return result;
}
injectSystemResolvers(