Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where selection set flattening uses the wrong parent type #6874

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ export class SelectionSetToObject<Config extends ParsedDocumentsConfig = ParsedD
}

protected flattenSelectionSet(
selections: ReadonlyArray<SelectionNode>
selections: ReadonlyArray<SelectionNode>,
parentSchemaType?: GraphQLObjectType<any, any>
): Map<string, Array<SelectionNode | FragmentSpreadUsage>> {
const selectionNodesByTypeName = new Map<string, Array<SelectionNode | FragmentSpreadUsage>>();
const inlineFragmentSelections: InlineFragmentNode[] = [];
Expand All @@ -265,10 +266,16 @@ export class SelectionSetToObject<Config extends ParsedDocumentsConfig = ParsedD
}

if (fieldNodes.length) {
inlineFragmentSelections.push(this._createInlineFragmentForFieldNodes(this._parentSchemaType, fieldNodes));
inlineFragmentSelections.push(
this._createInlineFragmentForFieldNodes(parentSchemaType ?? this._parentSchemaType, fieldNodes)
);
}

this._collectInlineFragments(this._parentSchemaType, inlineFragmentSelections, selectionNodesByTypeName);
this._collectInlineFragments(
parentSchemaType ?? this._parentSchemaType,
inlineFragmentSelections,
selectionNodesByTypeName
);
const fragmentsUsage = this.buildFragmentSpreadsUsage(fragmentSpreads);

for (const [typeName, records] of Object.entries(fragmentsUsage)) {
Expand Down Expand Up @@ -419,7 +426,7 @@ export class SelectionSetToObject<Config extends ParsedDocumentsConfig = ParsedD
fragmentType.getTypes().find(objectType => objectType.name === parentSchemaType.name))
) {
// also process fields from fragment that apply for this parentType
const flatten = this.flattenSelectionSet(selectionNode.selectionNodes);
const flatten = this.flattenSelectionSet(selectionNode.selectionNodes, parentSchemaType);
const typeNodes = flatten.get(parentSchemaType.name) ?? [];
selectionNodes.push(...typeNodes);
for (const iinterface of parentSchemaType.getInterfaces()) {
Expand Down