@@ -1195,33 +1195,39 @@ function completeListValue(
1195
1195
// This is specified as a simple map, however we're optimizing the path
1196
1196
// where the list contains no Promises by avoiding creating another Promise.
1197
1197
let containsPromise = false ;
1198
- let previousAsyncPayloadRecord = asyncPayloadRecord ;
1199
1198
const completedResults : Array < unknown > = [ ] ;
1199
+ const iterator = result [ Symbol . iterator ] ( ) ;
1200
1200
let index = 0 ;
1201
- for ( const item of result ) {
1201
+ // eslint-disable-next-line no-constant-condition
1202
+ while ( true ) {
1202
1203
// No need to modify the info object containing the path,
1203
1204
// since from here on it is not ever accessed by resolver functions.
1204
- const itemPath = exeContext . addPath ( path , index , undefined ) ;
1205
1205
1206
1206
if (
1207
1207
stream &&
1208
1208
typeof stream . initialCount === 'number' &&
1209
1209
index >= stream . initialCount
1210
1210
) {
1211
- previousAsyncPayloadRecord = executeStreamField (
1212
- path ,
1213
- itemPath ,
1214
- item ,
1211
+ executeStreamIterator (
1212
+ index ,
1213
+ iterator ,
1215
1214
exeContext ,
1216
1215
fieldGroup ,
1217
1216
info ,
1218
1217
itemType ,
1219
- previousAsyncPayloadRecord ,
1218
+ path ,
1219
+ asyncPayloadRecord ,
1220
1220
) ;
1221
- index ++ ;
1222
- continue ;
1221
+ break ;
1222
+ }
1223
+
1224
+ const { done, value : item } = iterator . next ( ) ;
1225
+ if ( done ) {
1226
+ break ;
1223
1227
}
1224
1228
1229
+ const itemPath = exeContext . addPath ( path , index , undefined ) ;
1230
+
1225
1231
if (
1226
1232
completeListItemValue (
1227
1233
item ,
@@ -1886,107 +1892,125 @@ function executeDeferredFragment(
1886
1892
asyncPayloadRecord . addData ( promiseOrData ) ;
1887
1893
}
1888
1894
1889
- function executeStreamField (
1890
- path : Path ,
1891
- itemPath : Path ,
1892
- item : PromiseOrValue < unknown > ,
1895
+ function executeStreamIterator (
1896
+ initialIndex : number ,
1897
+ iterator : Iterator < unknown > ,
1893
1898
exeContext : ExecutionContext ,
1894
1899
fieldGroup : FieldGroup ,
1895
1900
info : GraphQLResolveInfo ,
1896
1901
itemType : GraphQLOutputType ,
1902
+ path : Path ,
1897
1903
parentContext ?: AsyncPayloadRecord ,
1898
- ) : AsyncPayloadRecord {
1899
- const asyncPayloadRecord = new StreamRecord ( {
1900
- deferDepth : parentContext ?. deferDepth ,
1901
- path : itemPath ,
1902
- parentContext,
1903
- exeContext,
1904
- } ) ;
1905
- if ( isPromise ( item ) ) {
1906
- const completedItems = completePromisedValue (
1907
- exeContext ,
1908
- itemType ,
1909
- fieldGroup ,
1910
- info ,
1911
- itemPath ,
1912
- item ,
1913
- asyncPayloadRecord ,
1914
- ) . then (
1915
- ( value ) => [ value ] ,
1916
- ( error ) => {
1917
- asyncPayloadRecord . errors . push ( error ) ;
1918
- filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
1919
- return null ;
1920
- } ,
1921
- ) ;
1904
+ ) : void {
1905
+ let index = initialIndex ;
1906
+ const deferDepth = parentContext ?. deferDepth ;
1907
+ let previousAsyncPayloadRecord = parentContext ?? undefined ;
1908
+ // eslint-disable-next-line no-constant-condition
1909
+ while ( true ) {
1910
+ const { done, value : item } = iterator . next ( ) ;
1911
+ if ( done ) {
1912
+ break ;
1913
+ }
1922
1914
1923
- asyncPayloadRecord . addItems ( completedItems ) ;
1924
- return asyncPayloadRecord ;
1925
- }
1915
+ const itemPath = exeContext . addPath ( path , index , undefined ) ;
1916
+ const asyncPayloadRecord = new StreamRecord ( {
1917
+ deferDepth,
1918
+ path : itemPath ,
1919
+ parentContext : previousAsyncPayloadRecord ,
1920
+ exeContext,
1921
+ } ) ;
1926
1922
1927
- let completedItem : PromiseOrValue < unknown > ;
1928
- try {
1929
- try {
1930
- completedItem = completeValue (
1923
+ if ( isPromise ( item ) ) {
1924
+ const completedItems = completePromisedValue (
1931
1925
exeContext ,
1932
1926
itemType ,
1933
1927
fieldGroup ,
1934
1928
info ,
1935
1929
itemPath ,
1936
1930
item ,
1937
1931
asyncPayloadRecord ,
1932
+ ) . then (
1933
+ ( value ) => [ value ] ,
1934
+ ( error ) => {
1935
+ asyncPayloadRecord . errors . push ( error ) ;
1936
+ filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
1937
+ return null ;
1938
+ } ,
1938
1939
) ;
1939
- } catch ( rawError ) {
1940
- const error = locatedError (
1941
- rawError ,
1942
- toNodes ( fieldGroup ) ,
1943
- pathToArray ( itemPath ) ,
1944
- ) ;
1945
- completedItem = handleFieldError (
1946
- error ,
1947
- itemType ,
1948
- asyncPayloadRecord . errors ,
1949
- ) ;
1950
- filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1940
+
1941
+ asyncPayloadRecord . addItems ( completedItems ) ;
1942
+ previousAsyncPayloadRecord = asyncPayloadRecord ;
1943
+ index ++ ;
1944
+ continue ;
1951
1945
}
1952
- } catch ( error ) {
1953
- asyncPayloadRecord . errors . push ( error ) ;
1954
- filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
1955
- asyncPayloadRecord . addItems ( null ) ;
1956
- return asyncPayloadRecord ;
1957
- }
1958
1946
1959
- if ( isPromise ( completedItem ) ) {
1960
- const completedItems = completedItem
1961
- . then ( undefined , ( rawError ) => {
1947
+ let completedItem : PromiseOrValue < unknown > ;
1948
+ try {
1949
+ try {
1950
+ completedItem = completeValue (
1951
+ exeContext ,
1952
+ itemType ,
1953
+ fieldGroup ,
1954
+ info ,
1955
+ itemPath ,
1956
+ item ,
1957
+ asyncPayloadRecord ,
1958
+ ) ;
1959
+ } catch ( rawError ) {
1962
1960
const error = locatedError (
1963
1961
rawError ,
1964
1962
toNodes ( fieldGroup ) ,
1965
1963
pathToArray ( itemPath ) ,
1966
1964
) ;
1967
- const handledError = handleFieldError (
1965
+ completedItem = handleFieldError (
1968
1966
error ,
1969
1967
itemType ,
1970
1968
asyncPayloadRecord . errors ,
1971
1969
) ;
1972
1970
filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1973
- return handledError ;
1974
- } )
1975
- . then (
1976
- ( value ) => [ value ] ,
1977
- ( error ) => {
1978
- asyncPayloadRecord . errors . push ( error ) ;
1979
- filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
1980
- return null ;
1981
- } ,
1982
- ) ;
1971
+ }
1972
+ } catch ( error ) {
1973
+ asyncPayloadRecord . errors . push ( error ) ;
1974
+ filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
1975
+ asyncPayloadRecord . addItems ( null ) ;
1976
+ previousAsyncPayloadRecord = asyncPayloadRecord ;
1977
+ index ++ ;
1978
+ continue ;
1979
+ }
1983
1980
1984
- asyncPayloadRecord . addItems ( completedItems ) ;
1985
- return asyncPayloadRecord ;
1986
- }
1981
+ if ( isPromise ( completedItem ) ) {
1982
+ const completedItems = completedItem
1983
+ . then ( undefined , ( rawError ) => {
1984
+ const error = locatedError (
1985
+ rawError ,
1986
+ toNodes ( fieldGroup ) ,
1987
+ pathToArray ( itemPath ) ,
1988
+ ) ;
1989
+ const handledError = handleFieldError (
1990
+ error ,
1991
+ itemType ,
1992
+ asyncPayloadRecord . errors ,
1993
+ ) ;
1994
+ filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1995
+ return handledError ;
1996
+ } )
1997
+ . then (
1998
+ ( value ) => [ value ] ,
1999
+ ( error ) => {
2000
+ asyncPayloadRecord . errors . push ( error ) ;
2001
+ filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
2002
+ return null ;
2003
+ } ,
2004
+ ) ;
2005
+
2006
+ asyncPayloadRecord . addItems ( completedItems ) ;
2007
+ } else {
2008
+ asyncPayloadRecord . addItems ( [ completedItem ] ) ;
2009
+ }
1987
2010
1988
- asyncPayloadRecord . addItems ( [ completedItem ] ) ;
1989
- return asyncPayloadRecord ;
2011
+ previousAsyncPayloadRecord = asyncPayloadRecord ;
2012
+ index ++ ;
2013
+ }
1990
2014
}
1991
2015
1992
2016
async function executeStreamAsyncIteratorItem (
0 commit comments