Skip to content

Commit e1fb65a

Browse files
sachindshindeyaacovCR
authored andcommitted
Modify collectConflictsBetweenFieldsAndFragment() to track seen fragments when recursing into fragments (but not when recursing into fields, to save memory)
1 parent 997923d commit e1fb65a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Diff for: src/validation/rules/OverlappingFieldsCanBeMergedRule.ts

+11
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ function findConflictsWithinSelectionSet(
200200
conflicts,
201201
cachedFieldsAndFragmentNames,
202202
comparedFragmentPairs,
203+
null,
203204
false,
204205
fieldMap,
205206
fragmentNames[i],
@@ -231,10 +232,15 @@ function collectConflictsBetweenFieldsAndFragment(
231232
conflicts: Array<Conflict>,
232233
cachedFieldsAndFragmentNames: Map<SelectionSetNode, FieldsAndFragmentNames>,
233234
comparedFragmentPairs: PairSet,
235+
comparedFragmentsForFields: null | Set<string>,
234236
areMutuallyExclusive: boolean,
235237
fieldMap: NodeAndDefCollection,
236238
fragmentName: string,
237239
): void {
240+
if (comparedFragmentsForFields?.has(fragmentName)) {
241+
return;
242+
}
243+
238244
const fragment = context.getFragment(fragmentName);
239245
if (!fragment) {
240246
return;
@@ -266,12 +272,15 @@ function collectConflictsBetweenFieldsAndFragment(
266272

267273
// (E) Then collect any conflicts between the provided collection of fields
268274
// and any fragment names found in the given fragment.
275+
const newComparedFragmentsForFields =
276+
comparedFragmentsForFields ?? new Set([fragmentName]);
269277
for (const referencedFragmentName of referencedFragmentNames) {
270278
collectConflictsBetweenFieldsAndFragment(
271279
context,
272280
conflicts,
273281
cachedFieldsAndFragmentNames,
274282
comparedFragmentPairs,
283+
newComparedFragmentsForFields,
275284
areMutuallyExclusive,
276285
fieldMap,
277286
referencedFragmentName,
@@ -414,6 +423,7 @@ function findConflictsBetweenSubSelectionSets(
414423
conflicts,
415424
cachedFieldsAndFragmentNames,
416425
comparedFragmentPairs,
426+
null,
417427
areMutuallyExclusive,
418428
fieldMap1,
419429
fragmentName2,
@@ -428,6 +438,7 @@ function findConflictsBetweenSubSelectionSets(
428438
conflicts,
429439
cachedFieldsAndFragmentNames,
430440
comparedFragmentPairs,
441+
null,
431442
areMutuallyExclusive,
432443
fieldMap2,
433444
fragmentName1,

0 commit comments

Comments
 (0)