Skip to content

Commit

Permalink
Prevent Infinite Loop in OverlappingFieldsCanBeMergedRule
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslt committed Dec 24, 2021
1 parent 533b423 commit f130906
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/validation/__tests__/OverlappingFieldsCanBeMergedRule-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,17 @@ describe('Validate: Overlapping fields can be merged', () => {
`);
});

it('does not infinite loop on immediately recursive fragment mentionned in queries', () => {
expectValid(`
query myQuery {
todoRemove
...fragA
}
fragment fragA on Query { ...fragA }
`);
});

it('does not infinite loop on transitively recursive fragment', () => {
expectValid(`
fragment fragA on Human { name, ...fragB }
Expand Down
4 changes: 4 additions & 0 deletions src/validation/rules/OverlappingFieldsCanBeMergedRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ function collectConflictsBetweenFieldsAndFragment(
// (E) Then collect any conflicts between the provided collection of fields
// and any fragment names found in the given fragment.
for (const referencedFragmentName of referencedFragmentNames) {
if (referencedFragmentName === fragmentName) {
continue;
}

collectConflictsBetweenFieldsAndFragment(
context,
conflicts,
Expand Down

0 comments on commit f130906

Please sign in to comment.