@@ -363,7 +363,9 @@ function executeImpl(
363
363
...initialResult ,
364
364
hasNext : true ,
365
365
} ,
366
- subsequentResults : yieldSubsequentPayloads ( exeContext ) ,
366
+ subsequentResults : yieldSubsequentPayloads (
367
+ exeContext . subsequentPayloads ,
368
+ ) ,
367
369
} ;
368
370
}
369
371
return initialResult ;
@@ -381,7 +383,9 @@ function executeImpl(
381
383
...initialResult ,
382
384
hasNext : true ,
383
385
} ,
384
- subsequentResults : yieldSubsequentPayloads ( exeContext ) ,
386
+ subsequentResults : yieldSubsequentPayloads (
387
+ exeContext . subsequentPayloads ,
388
+ ) ,
385
389
} ;
386
390
}
387
391
return initialResult ;
@@ -750,15 +754,23 @@ function executeField(
750
754
return completed . then ( undefined , ( rawError ) => {
751
755
const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
752
756
addError ( rawError , fieldNodes , returnType , path , errors ) ;
753
- filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
757
+ filterSubsequentPayloads (
758
+ exeContext . subsequentPayloads ,
759
+ path ,
760
+ asyncPayloadRecord ,
761
+ ) ;
754
762
return null ;
755
763
} ) ;
756
764
}
757
765
return completed ;
758
766
} catch ( rawError ) {
759
767
const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
760
768
addError ( rawError , fieldNodes , returnType , path , errors ) ;
761
- filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
769
+ filterSubsequentPayloads (
770
+ exeContext . subsequentPayloads ,
771
+ path ,
772
+ asyncPayloadRecord ,
773
+ ) ;
762
774
return null ;
763
775
}
764
776
}
@@ -950,7 +962,11 @@ async function completePromisedValue(
950
962
} catch ( rawError ) {
951
963
const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
952
964
addError ( rawError , fieldNodes , returnType , path , errors ) ;
953
- filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
965
+ filterSubsequentPayloads (
966
+ exeContext . subsequentPayloads ,
967
+ path ,
968
+ asyncPayloadRecord ,
969
+ ) ;
954
970
return null ;
955
971
}
956
972
}
@@ -1230,7 +1246,11 @@ function completeListItemValue(
1230
1246
/* c8 ignore start */ asyncPayloadRecord ?. errors ??
1231
1247
/* c8 ignore stop */ exeContext . errors ;
1232
1248
addError ( rawError , fieldNodes , itemType , itemPath , errors ) ;
1233
- filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1249
+ filterSubsequentPayloads (
1250
+ exeContext . subsequentPayloads ,
1251
+ itemPath ,
1252
+ asyncPayloadRecord ,
1253
+ ) ;
1234
1254
return null ;
1235
1255
} ) ,
1236
1256
) ;
@@ -1245,7 +1265,11 @@ function completeListItemValue(
1245
1265
/* c8 ignore start */ asyncPayloadRecord ?. errors ??
1246
1266
/* c8 ignore stop */ exeContext . errors ;
1247
1267
addError ( rawError , fieldNodes , itemType , itemPath , errors ) ;
1248
- filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1268
+ filterSubsequentPayloads (
1269
+ exeContext . subsequentPayloads ,
1270
+ itemPath ,
1271
+ asyncPayloadRecord ,
1272
+ ) ;
1249
1273
completedResults . push ( null ) ;
1250
1274
}
1251
1275
@@ -1838,7 +1862,11 @@ function executeStreamField(
1838
1862
( value ) => [ value ] ,
1839
1863
( error ) => {
1840
1864
asyncPayloadRecord . errors . push ( error ) ;
1841
- filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
1865
+ filterSubsequentPayloads (
1866
+ exeContext . subsequentPayloads ,
1867
+ path ,
1868
+ asyncPayloadRecord ,
1869
+ ) ;
1842
1870
return null ;
1843
1871
} ,
1844
1872
) ;
@@ -1868,11 +1896,19 @@ function executeStreamField(
1868
1896
asyncPayloadRecord . errors ,
1869
1897
) ;
1870
1898
completedItem = null ;
1871
- filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1899
+ filterSubsequentPayloads (
1900
+ exeContext . subsequentPayloads ,
1901
+ itemPath ,
1902
+ asyncPayloadRecord ,
1903
+ ) ;
1872
1904
}
1873
1905
} catch ( error ) {
1874
1906
asyncPayloadRecord . errors . push ( error ) ;
1875
- filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
1907
+ filterSubsequentPayloads (
1908
+ exeContext . subsequentPayloads ,
1909
+ path ,
1910
+ asyncPayloadRecord ,
1911
+ ) ;
1876
1912
asyncPayloadRecord . addItems ( null ) ;
1877
1913
return asyncPayloadRecord ;
1878
1914
}
@@ -1887,14 +1923,22 @@ function executeStreamField(
1887
1923
itemPath ,
1888
1924
asyncPayloadRecord . errors ,
1889
1925
) ;
1890
- filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1926
+ filterSubsequentPayloads (
1927
+ exeContext . subsequentPayloads ,
1928
+ itemPath ,
1929
+ asyncPayloadRecord ,
1930
+ ) ;
1891
1931
return null ;
1892
1932
} )
1893
1933
. then (
1894
1934
( value ) => [ value ] ,
1895
1935
( error ) => {
1896
1936
asyncPayloadRecord . errors . push ( error ) ;
1897
- filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
1937
+ filterSubsequentPayloads (
1938
+ exeContext . subsequentPayloads ,
1939
+ path ,
1940
+ asyncPayloadRecord ,
1941
+ ) ;
1898
1942
return null ;
1899
1943
} ,
1900
1944
) ;
@@ -1959,7 +2003,11 @@ async function executeStreamIteratorItem(
1959
2003
itemPath ,
1960
2004
asyncPayloadRecord . errors ,
1961
2005
) ;
1962
- filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
2006
+ filterSubsequentPayloads (
2007
+ exeContext . subsequentPayloads ,
2008
+ itemPath ,
2009
+ asyncPayloadRecord ,
2010
+ ) ;
1963
2011
return null ;
1964
2012
} ) ;
1965
2013
}
@@ -1972,7 +2020,11 @@ async function executeStreamIteratorItem(
1972
2020
itemPath ,
1973
2021
asyncPayloadRecord . errors ,
1974
2022
) ;
1975
- filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
2023
+ filterSubsequentPayloads (
2024
+ exeContext . subsequentPayloads ,
2025
+ itemPath ,
2026
+ asyncPayloadRecord ,
2027
+ ) ;
1976
2028
return { done : false , value : null } ;
1977
2029
}
1978
2030
}
@@ -2015,7 +2067,11 @@ async function executeStreamIterator(
2015
2067
) ;
2016
2068
} catch ( error ) {
2017
2069
asyncPayloadRecord . errors . push ( error ) ;
2018
- filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
2070
+ filterSubsequentPayloads (
2071
+ exeContext . subsequentPayloads ,
2072
+ path ,
2073
+ asyncPayloadRecord ,
2074
+ ) ;
2019
2075
asyncPayloadRecord . addItems ( null ) ;
2020
2076
// entire stream has errored and bubbled upwards
2021
2077
if ( iterator ?. return ) {
@@ -2034,7 +2090,11 @@ async function executeStreamIterator(
2034
2090
( value ) => [ value ] ,
2035
2091
( error ) => {
2036
2092
asyncPayloadRecord . errors . push ( error ) ;
2037
- filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
2093
+ filterSubsequentPayloads (
2094
+ exeContext . subsequentPayloads ,
2095
+ path ,
2096
+ asyncPayloadRecord ,
2097
+ ) ;
2038
2098
return null ;
2039
2099
} ,
2040
2100
) ;
@@ -2053,12 +2113,12 @@ async function executeStreamIterator(
2053
2113
}
2054
2114
2055
2115
function filterSubsequentPayloads (
2056
- exeContext : ExecutionContext ,
2116
+ subsequentPayloads : Set < AsyncPayloadRecord > ,
2057
2117
nullPath : Path ,
2058
2118
currentAsyncRecord : AsyncPayloadRecord | undefined ,
2059
2119
) : void {
2060
2120
const nullPathArray = pathToArray ( nullPath ) ;
2061
- exeContext . subsequentPayloads . forEach ( ( asyncRecord ) => {
2121
+ subsequentPayloads . forEach ( ( asyncRecord ) => {
2062
2122
if ( asyncRecord === currentAsyncRecord ) {
2063
2123
// don't remove payload from where error originates
2064
2124
return ;
@@ -2075,20 +2135,20 @@ function filterSubsequentPayloads(
2075
2135
// ignore error
2076
2136
} ) ;
2077
2137
}
2078
- exeContext . subsequentPayloads . delete ( asyncRecord ) ;
2138
+ subsequentPayloads . delete ( asyncRecord ) ;
2079
2139
} ) ;
2080
2140
}
2081
2141
2082
2142
function getCompletedIncrementalResults (
2083
- exeContext : ExecutionContext ,
2143
+ subsequentPayloads : Set < AsyncPayloadRecord > ,
2084
2144
) : Array < IncrementalResult > {
2085
2145
const incrementalResults : Array < IncrementalResult > = [ ] ;
2086
- for ( const asyncPayloadRecord of exeContext . subsequentPayloads ) {
2146
+ for ( const asyncPayloadRecord of subsequentPayloads ) {
2087
2147
const incrementalResult : IncrementalResult = { } ;
2088
2148
if ( ! asyncPayloadRecord . isCompleted ) {
2089
2149
continue ;
2090
2150
}
2091
- exeContext . subsequentPayloads . delete ( asyncPayloadRecord ) ;
2151
+ subsequentPayloads . delete ( asyncPayloadRecord ) ;
2092
2152
if ( isStreamPayload ( asyncPayloadRecord ) ) {
2093
2153
const items = asyncPayloadRecord . items ;
2094
2154
if ( asyncPayloadRecord . isCompletedIterator ) {
@@ -2114,7 +2174,7 @@ function getCompletedIncrementalResults(
2114
2174
}
2115
2175
2116
2176
function yieldSubsequentPayloads (
2117
- exeContext : ExecutionContext ,
2177
+ subsequentPayloads : Set < AsyncPayloadRecord > ,
2118
2178
) : AsyncGenerator < SubsequentIncrementalExecutionResult , void , void > {
2119
2179
let isDone = false ;
2120
2180
@@ -2125,17 +2185,15 @@ function yieldSubsequentPayloads(
2125
2185
return { value : undefined , done : true } ;
2126
2186
}
2127
2187
2128
- await Promise . race (
2129
- Array . from ( exeContext . subsequentPayloads ) . map ( ( p ) => p . promise ) ,
2130
- ) ;
2188
+ await Promise . race ( Array . from ( subsequentPayloads ) . map ( ( p ) => p . promise ) ) ;
2131
2189
2132
2190
if ( isDone ) {
2133
2191
// a different call to next has exhausted all payloads
2134
2192
return { value : undefined , done : true } ;
2135
2193
}
2136
2194
2137
- const incremental = getCompletedIncrementalResults ( exeContext ) ;
2138
- const hasNext = exeContext . subsequentPayloads . size > 0 ;
2195
+ const incremental = getCompletedIncrementalResults ( subsequentPayloads ) ;
2196
+ const hasNext = subsequentPayloads . size > 0 ;
2139
2197
2140
2198
if ( ! incremental . length && hasNext ) {
2141
2199
return next ( ) ;
@@ -2153,7 +2211,7 @@ function yieldSubsequentPayloads(
2153
2211
2154
2212
function returnStreamIterators ( ) {
2155
2213
const promises : Array < Promise < IteratorResult < unknown > > > = [ ] ;
2156
- exeContext . subsequentPayloads . forEach ( ( asyncPayloadRecord ) => {
2214
+ subsequentPayloads . forEach ( ( asyncPayloadRecord ) => {
2157
2215
if (
2158
2216
isStreamPayload ( asyncPayloadRecord ) &&
2159
2217
asyncPayloadRecord . iterator ?. return
0 commit comments