Skip to content

Instantly share code, notes, and snippets.

@benjie
Created December 20, 2023 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjie/b35ceb4289a30c224cee6db860ca33d2 to your computer and use it in GitHub Desktop.
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.
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