Skip to content

Commit

Permalink
Look through inline fragments to find selections
Browse files Browse the repository at this point in the history
  • Loading branch information
sgarner committed Aug 20, 2020
1 parent 80b1592 commit c155b22
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/RelationMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,26 @@ export class RelationMapper {
}

private findFieldInSelection(fieldName: string, selectionSet: SelectionSetNode): SelectionNode | undefined {
return selectionSet.selections.find(selectionNode => this.getNameFromNode(selectionNode) === fieldName);
let foundNode: SelectionNode | undefined = undefined;

for (const selectionNode of selectionSet.selections) {
if (foundNode !== undefined) {
break;
}

if (selectionNode.kind === 'InlineFragment') {
foundNode = this.findFieldInSelection(fieldName, selectionNode.selectionSet);

break;
}

if (this.getNameFromNode(selectionNode) === fieldName) {
foundNode = selectionNode;

break;
}
}

return foundNode;
}
}

0 comments on commit c155b22

Please sign in to comment.