@@ -7,8 +7,8 @@ import { isPromise } from '../jsutils/isPromise.js';
7
7
import type { Maybe } from '../jsutils/Maybe.js' ;
8
8
import { memoize3 } from '../jsutils/memoize3.js' ;
9
9
import type { ObjMap } from '../jsutils/ObjMap.js' ;
10
- import type { Path , PathFactory } from '../jsutils/Path.js' ;
11
- import { createPathFactory , pathToArray } from '../jsutils/Path.js' ;
10
+ import type { Path } from '../jsutils/Path.js' ;
11
+ import { pathToArray , Root } from '../jsutils/Path.js' ;
12
12
import { promiseForObject } from '../jsutils/promiseForObject.js' ;
13
13
import type { PromiseOrValue } from '../jsutils/PromiseOrValue.js' ;
14
14
import { promiseReduce } from '../jsutils/promiseReduce.js' ;
@@ -121,10 +121,10 @@ export interface ExecutionContext {
121
121
fieldResolver : GraphQLFieldResolver < any , any > ;
122
122
typeResolver : GraphQLTypeResolver < any , any > ;
123
123
subscribeFieldResolver : GraphQLFieldResolver < any , any > ;
124
- addPath : PathFactory ;
124
+ root : Root ;
125
125
errors : Array < GraphQLError > ;
126
126
subsequentPayloads : Set < AsyncPayloadRecord > ;
127
- branches : WeakMap < GroupedFieldSet , Set < Path | undefined > > ;
127
+ branches : WeakMap < GroupedFieldSet , Set < Path | Root > > ;
128
128
}
129
129
130
130
/**
@@ -502,7 +502,7 @@ export function buildExecutionContext(
502
502
fieldResolver : fieldResolver ?? defaultFieldResolver ,
503
503
typeResolver : typeResolver ?? defaultTypeResolver ,
504
504
subscribeFieldResolver : subscribeFieldResolver ?? defaultFieldResolver ,
505
- addPath : createPathFactory ( ) ,
505
+ root : new Root ( ) ,
506
506
subsequentPayloads : new Set ( ) ,
507
507
branches : new WeakMap ( ) ,
508
508
errors : [ ] ,
@@ -516,7 +516,7 @@ function buildPerEventExecutionContext(
516
516
return {
517
517
...exeContext ,
518
518
rootValue : payload ,
519
- addPath : createPathFactory ( ) ,
519
+ root : new Root ( ) ,
520
520
subsequentPayloads : new Set ( ) ,
521
521
branches : new WeakMap ( ) ,
522
522
errors : [ ] ,
@@ -526,7 +526,7 @@ function buildPerEventExecutionContext(
526
526
function shouldBranch (
527
527
groupedFieldSet : GroupedFieldSet ,
528
528
exeContext : ExecutionContext ,
529
- path : Path | undefined ,
529
+ path : Path | Root ,
530
530
) : boolean {
531
531
const set = exeContext . branches . get ( groupedFieldSet ) ;
532
532
if ( set === undefined ) {
@@ -563,7 +563,7 @@ function executeOperation(
563
563
rootType ,
564
564
operation ,
565
565
) ;
566
- const path = undefined ;
566
+ const path = new Root ( ) ;
567
567
let result ;
568
568
569
569
switch ( operation . operation ) {
@@ -622,13 +622,13 @@ function executeFieldsSerially(
622
622
exeContext : ExecutionContext ,
623
623
parentType : GraphQLObjectType ,
624
624
sourceValue : unknown ,
625
- path : Path | undefined ,
625
+ path : Path | Root ,
626
626
groupedFieldSet : GroupedFieldSet ,
627
627
) : PromiseOrValue < ObjMap < unknown > > {
628
628
return promiseReduce (
629
629
groupedFieldSet ,
630
630
( results , [ responseName , fieldGroup ] ) => {
631
- const fieldPath = exeContext . addPath ( path , responseName , parentType . name ) ;
631
+ const fieldPath = path . addPath ( responseName , parentType . name ) ;
632
632
633
633
if ( ! shouldExecute ( fieldGroup ) ) {
634
634
return results ;
@@ -672,7 +672,7 @@ function executeFields(
672
672
exeContext : ExecutionContext ,
673
673
parentType : GraphQLObjectType ,
674
674
sourceValue : unknown ,
675
- path : Path | undefined ,
675
+ path : Path | Root ,
676
676
groupedFieldSet : GroupedFieldSet ,
677
677
asyncPayloadRecord ?: AsyncPayloadRecord ,
678
678
) : PromiseOrValue < ObjMap < unknown > > {
@@ -681,7 +681,7 @@ function executeFields(
681
681
682
682
try {
683
683
for ( const [ responseName , fieldGroup ] of groupedFieldSet ) {
684
- const fieldPath = exeContext . addPath ( path , responseName , parentType . name ) ;
684
+ const fieldPath = path . addPath ( responseName , parentType . name ) ;
685
685
686
686
if ( shouldExecute ( fieldGroup , asyncPayloadRecord ?. deferDepth ) ) {
687
687
const result = executeField (
@@ -1121,7 +1121,7 @@ async function completeAsyncIteratorValue(
1121
1121
break ;
1122
1122
}
1123
1123
1124
- const itemPath = exeContext . addPath ( path , index , undefined ) ;
1124
+ const itemPath = path . addPath ( index , undefined ) ;
1125
1125
let iteration ;
1126
1126
try {
1127
1127
// eslint-disable-next-line no-await-in-loop
@@ -1207,7 +1207,7 @@ function completeListValue(
1207
1207
for ( const item of result ) {
1208
1208
// No need to modify the info object containing the path,
1209
1209
// since from here on it is not ever accessed by resolver functions.
1210
- const itemPath = exeContext . addPath ( path , index , undefined ) ;
1210
+ const itemPath = path . addPath ( index , undefined ) ;
1211
1211
1212
1212
if (
1213
1213
stream &&
@@ -1798,7 +1798,7 @@ function executeSubscription(
1798
1798
) ;
1799
1799
}
1800
1800
1801
- const path = exeContext . addPath ( undefined , responseName , rootType . name ) ;
1801
+ const path = exeContext . root . addPath ( responseName , rootType . name ) ;
1802
1802
const info = buildResolveInfo (
1803
1803
exeContext ,
1804
1804
fieldDef ,
@@ -1859,7 +1859,7 @@ function executeDeferredFragment(
1859
1859
sourceValue : unknown ,
1860
1860
groupedFieldSet : GroupedFieldSet ,
1861
1861
newDeferDepth : number ,
1862
- path ? : Path ,
1862
+ path : Path | Root ,
1863
1863
parentContext ?: AsyncPayloadRecord ,
1864
1864
) : void {
1865
1865
const asyncPayloadRecord = new DeferredFragmentRecord ( {
@@ -2079,7 +2079,7 @@ async function executeStreamIterator(
2079
2079
let previousAsyncPayloadRecord = parentContext ?? undefined ;
2080
2080
// eslint-disable-next-line no-constant-condition
2081
2081
while ( true ) {
2082
- const itemPath = exeContext . addPath ( path , index , undefined ) ;
2082
+ const itemPath = path . addPath ( index , undefined ) ;
2083
2083
const asyncPayloadRecord = new StreamRecord ( {
2084
2084
path : itemPath ,
2085
2085
deferDepth,
@@ -2282,7 +2282,7 @@ class DeferredFragmentRecord {
2282
2282
_exeContext : ExecutionContext ;
2283
2283
_resolve ?: ( arg : PromiseOrValue < ObjMap < unknown > | null > ) => void ;
2284
2284
constructor ( opts : {
2285
- path : Path | undefined ;
2285
+ path : Path | Root ;
2286
2286
deferDepth : number | undefined ;
2287
2287
parentContext : AsyncPayloadRecord | undefined ;
2288
2288
exeContext : ExecutionContext ;
@@ -2330,7 +2330,7 @@ class StreamRecord {
2330
2330
_exeContext : ExecutionContext ;
2331
2331
_resolve ?: ( arg : PromiseOrValue < Array < unknown > | null > ) => void ;
2332
2332
constructor ( opts : {
2333
- path : Path | undefined ;
2333
+ path : Path | Root ;
2334
2334
deferDepth : number | undefined ;
2335
2335
iterator ?: AsyncIterator < unknown > ;
2336
2336
parentContext : AsyncPayloadRecord | undefined ;
0 commit comments