@@ -48,7 +48,7 @@ import { GraphQLStreamDirective } from '../type/directives.js';
48
48
import type { GraphQLSchema } from '../type/schema.js' ;
49
49
import { assertValidSchema } from '../type/validate.js' ;
50
50
51
- import type { TaggedFieldNode } from './collectFields.js' ;
51
+ import type { GroupedFieldSet , TaggedFieldNode } from './collectFields.js' ;
52
52
import {
53
53
collectFields ,
54
54
collectSubfields as _collectSubfields ,
@@ -123,7 +123,7 @@ export interface ExecutionContext {
123
123
subscribeFieldResolver : GraphQLFieldResolver < any , any > ;
124
124
errors : Array < GraphQLError > ;
125
125
subsequentPayloads : Set < AsyncPayloadRecord > ;
126
- branches : Set < string > ;
126
+ branches : WeakMap < GroupedFieldSet , Set < string > > ;
127
127
}
128
128
129
129
/**
@@ -502,7 +502,7 @@ export function buildExecutionContext(
502
502
typeResolver : typeResolver ?? defaultTypeResolver ,
503
503
subscribeFieldResolver : subscribeFieldResolver ?? defaultFieldResolver ,
504
504
subsequentPayloads : new Set ( ) ,
505
- branches : new Set ( ) ,
505
+ branches : new WeakMap ( ) ,
506
506
errors : [ ] ,
507
507
} ;
508
508
}
@@ -515,18 +515,24 @@ function buildPerEventExecutionContext(
515
515
...exeContext ,
516
516
rootValue : payload ,
517
517
subsequentPayloads : new Set ( ) ,
518
- branches : new Set ( ) ,
518
+ branches : new WeakMap ( ) ,
519
519
errors : [ ] ,
520
520
} ;
521
521
}
522
522
523
523
function shouldBranch (
524
524
exeContext : ExecutionContext ,
525
+ groupedFieldSet : GroupedFieldSet ,
525
526
path : Path | undefined ,
526
527
) : boolean {
528
+ const set = exeContext . branches . get ( groupedFieldSet ) ;
527
529
const key = pathToArray ( path ) . join ( '.' ) ;
528
- if ( ! exeContext . branches . has ( key ) ) {
529
- exeContext . branches . add ( key ) ;
530
+ if ( set === undefined ) {
531
+ exeContext . branches . set ( groupedFieldSet , new Set ( [ key ] ) ) ;
532
+ return true ;
533
+ }
534
+ if ( ! set . has ( key ) ) {
535
+ set . add ( key ) ;
530
536
return true ;
531
537
}
532
538
return false ;
@@ -591,7 +597,10 @@ function executeOperation(
591
597
) ;
592
598
}
593
599
594
- if ( newDeferDepth !== undefined && shouldBranch ( exeContext , path ) ) {
600
+ if (
601
+ newDeferDepth !== undefined &&
602
+ shouldBranch ( exeContext , groupedFieldSet , path )
603
+ ) {
595
604
executeDeferredFragment (
596
605
exeContext ,
597
606
rootType ,
@@ -1587,7 +1596,10 @@ function collectAndExecuteSubfields(
1587
1596
asyncPayloadRecord ,
1588
1597
) ;
1589
1598
1590
- if ( newDeferDepth !== undefined && shouldBranch ( exeContext , path ) ) {
1599
+ if (
1600
+ newDeferDepth !== undefined &&
1601
+ shouldBranch ( exeContext , groupedFieldSet , path )
1602
+ ) {
1591
1603
executeDeferredFragment (
1592
1604
exeContext ,
1593
1605
returnType ,
0 commit comments