@@ -207,26 +207,15 @@ function findConflictsWithinSelectionSet(
207
207
discoveredFragments ,
208
208
) ;
209
209
210
- // (E) Then collect any conflicts between the provided collection of fields
211
- // and any fragment names found in the given fragment.
212
- while ( discoveredFragments . length !== 0 ) {
213
- const item = discoveredFragments . pop ( ) ;
214
- if ( ! item || comparedFragmentPairs . has ( item [ 1 ] , item [ 0 ] , false ) ) {
215
- continue ;
216
- }
217
- const [ fragmentName , referencedFragmentName ] = item ;
218
- comparedFragmentPairs . add ( referencedFragmentName , fragmentName , false ) ;
219
- collectConflictsBetweenFieldsAndFragment (
220
- context ,
221
- conflicts ,
222
- cachedFieldsAndFragmentNames ,
223
- comparedFragmentPairs ,
224
- false ,
225
- fieldMap ,
226
- referencedFragmentName ,
227
- discoveredFragments ,
228
- ) ;
229
- }
210
+ processDiscoveredFragments (
211
+ context ,
212
+ conflicts ,
213
+ cachedFieldsAndFragmentNames ,
214
+ comparedFragmentPairs ,
215
+ false ,
216
+ fieldMap ,
217
+ discoveredFragments ,
218
+ )
230
219
// (C) Then compare this fragment with all other fragments found in this
231
220
// selection set to collect conflicts between fragments spread together.
232
221
// This compares each item in the list of fragment names to every other
@@ -439,33 +428,15 @@ function findConflictsBetweenSubSelectionSets(
439
428
) ;
440
429
}
441
430
442
- // (E) Then collect any conflicts between the provided collection of fields
443
- // and any fragment names found in the given fragment.
444
- while ( discoveredFragments . length !== 0 ) {
445
- const item = discoveredFragments . pop ( ) ;
446
- if (
447
- ! item ||
448
- comparedFragmentPairs . has ( item [ 1 ] , item [ 0 ] , areMutuallyExclusive )
449
- ) {
450
- continue ;
451
- }
452
- const [ fragmentName , referencedFragmentName ] = item ;
453
- comparedFragmentPairs . add (
454
- referencedFragmentName ,
455
- fragmentName ,
456
- areMutuallyExclusive ,
457
- ) ;
458
- collectConflictsBetweenFieldsAndFragment (
459
- context ,
460
- conflicts ,
461
- cachedFieldsAndFragmentNames ,
462
- comparedFragmentPairs ,
463
- areMutuallyExclusive ,
464
- fieldMap1 ,
465
- referencedFragmentName ,
466
- discoveredFragments ,
467
- ) ;
468
- }
431
+ processDiscoveredFragments (
432
+ context ,
433
+ conflicts ,
434
+ cachedFieldsAndFragmentNames ,
435
+ comparedFragmentPairs ,
436
+ areMutuallyExclusive ,
437
+ fieldMap1 ,
438
+ discoveredFragments ,
439
+ )
469
440
470
441
// (I) Then collect conflicts between the second collection of fields and
471
442
// those referenced by each fragment name associated with the first.
@@ -482,8 +453,46 @@ function findConflictsBetweenSubSelectionSets(
482
453
) ;
483
454
}
484
455
485
- // (E) Then collect any conflicts between the provided collection of fields
486
- // and any fragment names found in the given fragment.
456
+ processDiscoveredFragments (
457
+ context ,
458
+ conflicts ,
459
+ cachedFieldsAndFragmentNames ,
460
+ comparedFragmentPairs ,
461
+ areMutuallyExclusive ,
462
+ fieldMap2 ,
463
+ discoveredFragments ,
464
+ )
465
+
466
+ // (J) Also collect conflicts between any fragment names by the first and
467
+ // fragment names by the second. This compares each item in the first set of
468
+ // names to each item in the second set of names.
469
+ for ( const fragmentName1 of fragmentNames1 ) {
470
+ for ( const fragmentName2 of fragmentNames2 ) {
471
+ collectConflictsBetweenFragments (
472
+ context ,
473
+ conflicts ,
474
+ cachedFieldsAndFragmentNames ,
475
+ comparedFragmentPairs ,
476
+ areMutuallyExclusive ,
477
+ fragmentName1 ,
478
+ fragmentName2 ,
479
+ ) ;
480
+ }
481
+ }
482
+ return conflicts ;
483
+ }
484
+
485
+ // (E) Then collect any conflicts between the provided collection of fields
486
+ // and any fragment names found in the given fragment.
487
+ const processDiscoveredFragments = (
488
+ context : ValidationContext ,
489
+ conflicts : Array < Conflict > ,
490
+ cachedFieldsAndFragmentNames : Map < SelectionSetNode , FieldsAndFragmentNames > ,
491
+ comparedFragmentPairs : PairSet ,
492
+ areMutuallyExclusive : boolean ,
493
+ fieldMap : NodeAndDefCollection ,
494
+ discoveredFragments : Array < Array < string > > ,
495
+ ) => {
487
496
while ( discoveredFragments . length !== 0 ) {
488
497
const item = discoveredFragments . pop ( ) ;
489
498
if (
@@ -504,29 +513,11 @@ function findConflictsBetweenSubSelectionSets(
504
513
cachedFieldsAndFragmentNames ,
505
514
comparedFragmentPairs ,
506
515
areMutuallyExclusive ,
507
- fieldMap2 ,
516
+ fieldMap ,
508
517
referencedFragmentName ,
509
518
discoveredFragments ,
510
519
) ;
511
520
}
512
-
513
- // (J) Also collect conflicts between any fragment names by the first and
514
- // fragment names by the second. This compares each item in the first set of
515
- // names to each item in the second set of names.
516
- for ( const fragmentName1 of fragmentNames1 ) {
517
- for ( const fragmentName2 of fragmentNames2 ) {
518
- collectConflictsBetweenFragments (
519
- context ,
520
- conflicts ,
521
- cachedFieldsAndFragmentNames ,
522
- comparedFragmentPairs ,
523
- areMutuallyExclusive ,
524
- fragmentName1 ,
525
- fragmentName2 ,
526
- ) ;
527
- }
528
- }
529
- return conflicts ;
530
521
}
531
522
532
523
// Collect all Conflicts "within" one collection of fields.
0 commit comments