@@ -235,6 +235,13 @@ function collectConflictsBetweenFieldsAndFragment(
235
235
fieldMap : NodeAndDefCollection ,
236
236
fragmentName : string ,
237
237
) : void {
238
+ // Memoize so the fields and fragments are not compared for conflicts more
239
+ // than once.
240
+ if ( comparedFragmentPairs . has ( fieldMap , fragmentName , areMutuallyExclusive ) ) {
241
+ return ;
242
+ }
243
+ comparedFragmentPairs . add ( fieldMap , fragmentName , areMutuallyExclusive ) ;
244
+
238
245
const fragment = context . getFragment ( fragmentName ) ;
239
246
if ( ! fragment ) {
240
247
return ;
@@ -800,14 +807,19 @@ function subfieldConflicts(
800
807
* A way to keep track of pairs of things when the ordering of the pair does not matter.
801
808
*/
802
809
class PairSet {
803
- _data : Map < string , Map < string , boolean > > ;
810
+ _data : Map < string | NodeAndDefCollection , Map < string , boolean > > ;
804
811
805
812
constructor ( ) {
806
813
this . _data = new Map ( ) ;
807
814
}
808
815
809
- has ( a : string , b : string , areMutuallyExclusive : boolean ) : boolean {
810
- const [ key1 , key2 ] = a < b ? [ a , b ] : [ b , a ] ;
816
+ has (
817
+ a : string | NodeAndDefCollection ,
818
+ b : string ,
819
+ areMutuallyExclusive : boolean ,
820
+ ) : boolean {
821
+ const [ key1 , key2 ] =
822
+ typeof a !== 'string' ? [ a , b ] : a < b ? [ a , b ] : [ b , a ] ;
811
823
812
824
const result = this . _data . get ( key1 ) ?. get ( key2 ) ;
813
825
if ( result === undefined ) {
@@ -820,8 +832,13 @@ class PairSet {
820
832
return areMutuallyExclusive ? true : areMutuallyExclusive === result ;
821
833
}
822
834
823
- add ( a : string , b : string , areMutuallyExclusive : boolean ) : void {
824
- const [ key1 , key2 ] = a < b ? [ a , b ] : [ b , a ] ;
835
+ add (
836
+ a : string | NodeAndDefCollection ,
837
+ b : string ,
838
+ areMutuallyExclusive : boolean ,
839
+ ) : void {
840
+ const [ key1 , key2 ] =
841
+ typeof a !== 'string' ? [ a , b ] : a < b ? [ a , b ] : [ b , a ] ;
825
842
826
843
const map = this . _data . get ( key1 ) ;
827
844
if ( map === undefined ) {
0 commit comments