From e1fb65aac9dad01bc01a56ee9592d8960613f17e Mon Sep 17 00:00:00 2001 From: "Sachin D. Shinde" Date: Fri, 16 Aug 2024 14:44:38 -0700 Subject: [PATCH] Modify collectConflictsBetweenFieldsAndFragment() to track seen fragments when recursing into fragments (but not when recursing into fields, to save memory) --- .../rules/OverlappingFieldsCanBeMergedRule.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/validation/rules/OverlappingFieldsCanBeMergedRule.ts b/src/validation/rules/OverlappingFieldsCanBeMergedRule.ts index 0f2a9d4730..2aa38a3351 100644 --- a/src/validation/rules/OverlappingFieldsCanBeMergedRule.ts +++ b/src/validation/rules/OverlappingFieldsCanBeMergedRule.ts @@ -200,6 +200,7 @@ function findConflictsWithinSelectionSet( conflicts, cachedFieldsAndFragmentNames, comparedFragmentPairs, + null, false, fieldMap, fragmentNames[i], @@ -231,10 +232,15 @@ function collectConflictsBetweenFieldsAndFragment( conflicts: Array, cachedFieldsAndFragmentNames: Map, comparedFragmentPairs: PairSet, + comparedFragmentsForFields: null | Set, areMutuallyExclusive: boolean, fieldMap: NodeAndDefCollection, fragmentName: string, ): void { + if (comparedFragmentsForFields?.has(fragmentName)) { + return; + } + const fragment = context.getFragment(fragmentName); if (!fragment) { return; @@ -266,12 +272,15 @@ function collectConflictsBetweenFieldsAndFragment( // (E) Then collect any conflicts between the provided collection of fields // and any fragment names found in the given fragment. + const newComparedFragmentsForFields = + comparedFragmentsForFields ?? new Set([fragmentName]); for (const referencedFragmentName of referencedFragmentNames) { collectConflictsBetweenFieldsAndFragment( context, conflicts, cachedFieldsAndFragmentNames, comparedFragmentPairs, + newComparedFragmentsForFields, areMutuallyExclusive, fieldMap, referencedFragmentName, @@ -414,6 +423,7 @@ function findConflictsBetweenSubSelectionSets( conflicts, cachedFieldsAndFragmentNames, comparedFragmentPairs, + null, areMutuallyExclusive, fieldMap1, fragmentName2, @@ -428,6 +438,7 @@ function findConflictsBetweenSubSelectionSets( conflicts, cachedFieldsAndFragmentNames, comparedFragmentPairs, + null, areMutuallyExclusive, fieldMap2, fragmentName1,