@@ -1825,7 +1825,7 @@ function executeDeferredFragment(
1825
1825
label,
1826
1826
path,
1827
1827
parentContext,
1828
- exeContext,
1828
+ publisher : exeContext . publisher ,
1829
1829
} ) ;
1830
1830
1831
1831
let promiseOrData ;
@@ -1871,7 +1871,7 @@ function executeStreamField(
1871
1871
label,
1872
1872
path : itemPath ,
1873
1873
parentContext,
1874
- exeContext,
1874
+ publisher : exeContext . publisher ,
1875
1875
} ) ;
1876
1876
1877
1877
if ( isPromise ( item ) ) {
@@ -2054,7 +2054,7 @@ async function executeStreamAsyncIterator(
2054
2054
path : itemPath ,
2055
2055
parentContext : previousIncrementalDataRecord ,
2056
2056
asyncIterator,
2057
- exeContext,
2057
+ publisher : exeContext . publisher ,
2058
2058
} ) ;
2059
2059
2060
2060
let iteration ;
@@ -2179,11 +2179,7 @@ function getIncrementalResult(
2179
2179
for ( const incrementalDataRecord of completedRecords ) {
2180
2180
const incrementalResult : IncrementalResult = { } ;
2181
2181
for ( const child of incrementalDataRecord . children ) {
2182
- if ( child . isCompleted ) {
2183
- publisher . push ( child ) ;
2184
- } else {
2185
- publisher . introduce ( child ) ;
2186
- }
2182
+ child . publish ( ) ;
2187
2183
}
2188
2184
if ( isStreamItemsRecord ( incrementalDataRecord ) ) {
2189
2185
const items = incrementalDataRecord . items ;
@@ -2239,23 +2235,30 @@ class DeferredFragmentRecord {
2239
2235
parentContext : IncrementalDataRecord | undefined ;
2240
2236
children : Set < IncrementalDataRecord > ;
2241
2237
isCompleted : boolean ;
2242
- _exeContext : ExecutionContext ;
2238
+ _publisher : Publisher <
2239
+ IncrementalDataRecord ,
2240
+ SubsequentIncrementalExecutionResult
2241
+ > ;
2242
+
2243
2243
constructor ( opts : {
2244
2244
label : string | undefined ;
2245
2245
path : Path | undefined ;
2246
2246
parentContext : IncrementalDataRecord | undefined ;
2247
- exeContext : ExecutionContext ;
2247
+ publisher : Publisher <
2248
+ IncrementalDataRecord ,
2249
+ SubsequentIncrementalExecutionResult
2250
+ > ;
2248
2251
} ) {
2249
2252
this . type = 'defer' ;
2250
2253
this . label = opts . label ;
2251
2254
this . path = pathToArray ( opts . path ) ;
2252
2255
this . parentContext = opts . parentContext ;
2253
2256
this . errors = [ ] ;
2254
- this . _exeContext = opts . exeContext ;
2257
+ this . _publisher = opts . publisher ;
2255
2258
if ( this . parentContext ) {
2256
2259
this . parentContext . children . add ( this ) ;
2257
2260
} else {
2258
- this . _exeContext . publisher . introduce ( this ) ;
2261
+ this . _publisher . introduce ( this ) ;
2259
2262
}
2260
2263
this . children = new Set ( ) ;
2261
2264
this . isCompleted = false ;
@@ -2265,7 +2268,15 @@ class DeferredFragmentRecord {
2265
2268
addData ( data : ObjMap < unknown > | null ) {
2266
2269
this . data = data ;
2267
2270
this . isCompleted = true ;
2268
- this . _exeContext . publisher . release ( this ) ;
2271
+ this . _publisher . release ( this ) ;
2272
+ }
2273
+
2274
+ publish ( ) {
2275
+ if ( this . isCompleted ) {
2276
+ this . _publisher . push ( this ) ;
2277
+ } else {
2278
+ this . _publisher . introduce ( this ) ;
2279
+ }
2269
2280
}
2270
2281
}
2271
2282
@@ -2280,13 +2291,20 @@ class StreamItemsRecord {
2280
2291
asyncIterator : AsyncIterator < unknown > | undefined ;
2281
2292
isCompletedAsyncIterator ?: boolean ;
2282
2293
isCompleted : boolean ;
2283
- _exeContext : ExecutionContext ;
2294
+ _publisher : Publisher <
2295
+ IncrementalDataRecord ,
2296
+ SubsequentIncrementalExecutionResult
2297
+ > ;
2298
+
2284
2299
constructor ( opts : {
2285
2300
label : string | undefined ;
2286
2301
path : Path | undefined ;
2287
2302
asyncIterator ?: AsyncIterator < unknown > ;
2288
2303
parentContext : IncrementalDataRecord | undefined ;
2289
- exeContext : ExecutionContext ;
2304
+ publisher : Publisher <
2305
+ IncrementalDataRecord ,
2306
+ SubsequentIncrementalExecutionResult
2307
+ > ;
2290
2308
} ) {
2291
2309
this . type = 'stream' ;
2292
2310
this . items = null ;
@@ -2295,11 +2313,11 @@ class StreamItemsRecord {
2295
2313
this . parentContext = opts . parentContext ;
2296
2314
this . asyncIterator = opts . asyncIterator ;
2297
2315
this . errors = [ ] ;
2298
- this . _exeContext = opts . exeContext ;
2316
+ this . _publisher = opts . publisher ;
2299
2317
if ( this . parentContext ) {
2300
2318
this . parentContext . children . add ( this ) ;
2301
2319
} else {
2302
- this . _exeContext . publisher . introduce ( this ) ;
2320
+ this . _publisher . introduce ( this ) ;
2303
2321
}
2304
2322
this . children = new Set ( ) ;
2305
2323
this . isCompleted = false ;
@@ -2309,12 +2327,20 @@ class StreamItemsRecord {
2309
2327
addItems ( items : Array < unknown > | null ) {
2310
2328
this . items = items ;
2311
2329
this . isCompleted = true ;
2312
- this . _exeContext . publisher . release ( this ) ;
2330
+ this . _publisher . release ( this ) ;
2313
2331
}
2314
2332
2315
2333
setIsCompletedAsyncIterator ( ) {
2316
2334
this . isCompletedAsyncIterator = true ;
2317
2335
}
2336
+
2337
+ publish ( ) {
2338
+ if ( this . isCompleted ) {
2339
+ this . _publisher . push ( this ) ;
2340
+ } else {
2341
+ this . _publisher . introduce ( this ) ;
2342
+ }
2343
+ }
2318
2344
}
2319
2345
2320
2346
type IncrementalDataRecord = DeferredFragmentRecord | StreamItemsRecord ;
0 commit comments