Skip to content

Commit f130906

Browse files
committed
Prevent Infinite Loop in OverlappingFieldsCanBeMergedRule
1 parent 533b423 commit f130906

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/validation/__tests__/OverlappingFieldsCanBeMergedRule-test.ts

+11
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,17 @@ describe('Validate: Overlapping fields can be merged', () => {
10211021
`);
10221022
});
10231023

1024+
it('does not infinite loop on immediately recursive fragment mentionned in queries', () => {
1025+
expectValid(`
1026+
query myQuery {
1027+
todoRemove
1028+
...fragA
1029+
}
1030+
1031+
fragment fragA on Query { ...fragA }
1032+
`);
1033+
});
1034+
10241035
it('does not infinite loop on transitively recursive fragment', () => {
10251036
expectValid(`
10261037
fragment fragA on Human { name, ...fragB }

src/validation/rules/OverlappingFieldsCanBeMergedRule.ts

+4
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ function collectConflictsBetweenFieldsAndFragment(
267267
// (E) Then collect any conflicts between the provided collection of fields
268268
// and any fragment names found in the given fragment.
269269
for (const referencedFragmentName of referencedFragmentNames) {
270+
if (referencedFragmentName === fragmentName) {
271+
continue;
272+
}
273+
270274
collectConflictsBetweenFieldsAndFragment(
271275
context,
272276
conflicts,

0 commit comments

Comments
 (0)