From 34bce09e15bdf1751fd870274377feabb2cd5bde Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Wed, 19 Jun 2024 09:39:25 +0200 Subject: [PATCH] add missing invocations --- .../OverlappingFieldsCanBeMergedRule-test.ts | 1 + .../rules/OverlappingFieldsCanBeMergedRule.ts | 47 ++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/validation/__tests__/OverlappingFieldsCanBeMergedRule-test.ts b/src/validation/__tests__/OverlappingFieldsCanBeMergedRule-test.ts index 826f416174d..1f9c1764e29 100644 --- a/src/validation/__tests__/OverlappingFieldsCanBeMergedRule-test.ts +++ b/src/validation/__tests__/OverlappingFieldsCanBeMergedRule-test.ts @@ -1160,6 +1160,7 @@ describe('Validate: Overlapping fields can be merged', () => { __typename } `; + expectErrors(query).toDeepEqual([]); }); }); diff --git a/src/validation/rules/OverlappingFieldsCanBeMergedRule.ts b/src/validation/rules/OverlappingFieldsCanBeMergedRule.ts index 51e75d19507..ffeecc84f20 100644 --- a/src/validation/rules/OverlappingFieldsCanBeMergedRule.ts +++ b/src/validation/rules/OverlappingFieldsCanBeMergedRule.ts @@ -425,6 +425,7 @@ function findConflictsBetweenSubSelectionSets( // (I) Then collect conflicts between the first collection of fields and // those referenced by each fragment name associated with the second. + const discoveredFragments: Array> = []; for (const fragmentName2 of fragmentNames2) { collectConflictsBetweenFieldsAndFragment( context, @@ -434,7 +435,28 @@ function findConflictsBetweenSubSelectionSets( areMutuallyExclusive, fieldMap1, fragmentName2, - [], + discoveredFragments, + ); + } + + // (E) Then collect any conflicts between the provided collection of fields + // and any fragment names found in the given fragment. + while (discoveredFragments.length !== 0) { + const item = discoveredFragments.pop(); + if (!item || comparedFragmentPairs.has(item[1], item[0], areMutuallyExclusive)) { + continue; + } + const [fragmentName, referencedFragmentName] = item; + comparedFragmentPairs.add(referencedFragmentName, fragmentName, areMutuallyExclusive); + collectConflictsBetweenFieldsAndFragment( + context, + conflicts, + cachedFieldsAndFragmentNames, + comparedFragmentPairs, + false, + fieldMap1, + fragmentName, + discoveredFragments, ); } @@ -449,7 +471,28 @@ function findConflictsBetweenSubSelectionSets( areMutuallyExclusive, fieldMap2, fragmentName1, - [], + discoveredFragments, + ); + } + + // (E) Then collect any conflicts between the provided collection of fields + // and any fragment names found in the given fragment. + while (discoveredFragments.length !== 0) { + const item = discoveredFragments.pop(); + if (!item || comparedFragmentPairs.has(item[1], item[0], areMutuallyExclusive)) { + continue; + } + const [fragmentName, referencedFragmentName] = item; + comparedFragmentPairs.add(referencedFragmentName, fragmentName, areMutuallyExclusive); + collectConflictsBetweenFieldsAndFragment( + context, + conflicts, + cachedFieldsAndFragmentNames, + comparedFragmentPairs, + areMutuallyExclusive, + fieldMap2, + fragmentName, + discoveredFragments, ); }