Created
December 20, 2023 11:28
-
-
Save benjie/b35ceb4289a30c224cee6db860ca33d2 to your computer and use it in GitHub Desktop.
Patch for bug in OverlappingFieldsCanBeMergedRule in graphql@^15; apply with `patch-package` or `pnpm patch` or similar.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/validation/rules/OverlappingFieldsCanBeMergedRule.js b/validation/rules/OverlappingFieldsCanBeMergedRule.js | |
index 3fd18139ada7a3e766c78725c8a05ad18a42cddd..ec3cc13ce8efc700f39a4d0fc0f96331b7708906 100644 | |
--- a/validation/rules/OverlappingFieldsCanBeMergedRule.js | |
+++ b/validation/rules/OverlappingFieldsCanBeMergedRule.js | |
@@ -180,6 +180,23 @@ function collectConflictsBetweenFieldsAndFragment(context, conflicts, cachedFiel | |
// and any fragment names found in the given fragment. | |
for (var i = 0; i < fragmentNames2.length; i++) { | |
+ // Memoize so two fragments are not compared for conflicts more than once. | |
+ const referencedFragmentName = fragmentNames2[i]; | |
+ if ( | |
+ comparedFragmentPairs.has( | |
+ referencedFragmentName, | |
+ fragmentName, | |
+ areMutuallyExclusive, | |
+ ) | |
+ ) { | |
+ continue; | |
+ } | |
+ comparedFragmentPairs.add( | |
+ referencedFragmentName, | |
+ fragmentName, | |
+ areMutuallyExclusive, | |
+ ); | |
+ | |
collectConflictsBetweenFieldsAndFragment(context, conflicts, cachedFieldsAndFragmentNames, comparedFragmentPairs, areMutuallyExclusive, fieldMap, fragmentNames2[i]); | |
} | |
} // Collect all conflicts found between two fragments, including via spreading in |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment