Skip to content

Commit

Permalink
Modify collectConflictsBetweenFieldsAndFragment() to track seen fragm…
Browse files Browse the repository at this point in the history
…ents when recursing into fragments (but not when recursing into fields, to save memory)
  • Loading branch information
sachindshinde authored and yaacovCR committed Sep 23, 2024
1 parent 997923d commit e1fb65a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/validation/rules/OverlappingFieldsCanBeMergedRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ function findConflictsWithinSelectionSet(
conflicts,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,
null,
false,
fieldMap,
fragmentNames[i],
Expand Down Expand Up @@ -231,10 +232,15 @@ function collectConflictsBetweenFieldsAndFragment(
conflicts: Array<Conflict>,
cachedFieldsAndFragmentNames: Map<SelectionSetNode, FieldsAndFragmentNames>,
comparedFragmentPairs: PairSet,
comparedFragmentsForFields: null | Set<string>,
areMutuallyExclusive: boolean,
fieldMap: NodeAndDefCollection,
fragmentName: string,
): void {
if (comparedFragmentsForFields?.has(fragmentName)) {
return;
}

const fragment = context.getFragment(fragmentName);
if (!fragment) {
return;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -414,6 +423,7 @@ function findConflictsBetweenSubSelectionSets(
conflicts,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,
null,
areMutuallyExclusive,
fieldMap1,
fragmentName2,
Expand All @@ -428,6 +438,7 @@ function findConflictsBetweenSubSelectionSets(
conflicts,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,
null,
areMutuallyExclusive,
fieldMap2,
fragmentName1,
Expand Down

0 comments on commit e1fb65a

Please sign in to comment.