@@ -2163,12 +2163,12 @@ function firstSyncStreamItems(
2163
2163
info : GraphQLResolveInfo ,
2164
2164
itemType : GraphQLOutputType ,
2165
2165
) : StreamItemsRecord {
2166
- const path = streamRecord . path ;
2167
- const initialPath = addPath ( path , initialIndex , undefined ) ;
2168
-
2169
- const firstStreamItems : StreamItemsRecord = {
2166
+ return {
2170
2167
streamRecord,
2171
2168
result : Promise . resolve ( ) . then ( ( ) => {
2169
+ const path = streamRecord . path ;
2170
+ const initialPath = addPath ( path , initialIndex , undefined ) ;
2171
+
2172
2172
let result = completeStreamItems (
2173
2173
streamRecord ,
2174
2174
initialPath ,
@@ -2179,7 +2179,8 @@ function firstSyncStreamItems(
2179
2179
info ,
2180
2180
itemType ,
2181
2181
) ;
2182
- const results = [ result ] ;
2182
+ const firstStreamItems = { result } ;
2183
+ let currentStreamItems = firstStreamItems ;
2183
2184
let currentIndex = initialIndex ;
2184
2185
let iteration = iterator . next ( ) ;
2185
2186
let erroredSynchronously = false ;
@@ -2201,31 +2202,29 @@ function firstSyncStreamItems(
2201
2202
info ,
2202
2203
itemType ,
2203
2204
) ;
2204
- results . push ( result ) ;
2205
+
2206
+ const nextStreamItems : StreamItemsRecord = { streamRecord, result } ;
2207
+ currentStreamItems . result = prependNextStreamItems (
2208
+ currentStreamItems . result ,
2209
+ nextStreamItems ,
2210
+ ) ;
2211
+ currentStreamItems = nextStreamItems ;
2212
+
2205
2213
iteration = iterator . next ( ) ;
2206
2214
}
2207
2215
2208
- currentIndex = results . length - 1 ;
2209
2216
// If a non-reconcilable stream items result was encountered, then the stream terminates in error.
2210
2217
// Otherwise, add a stream terminator.
2211
- let currentResult = erroredSynchronously
2212
- ? results [ currentIndex ]
2213
- : prependNextStreamItems ( results [ currentIndex ] , {
2214
- streamRecord,
2215
- result : { streamRecord } ,
2216
- } ) ;
2217
-
2218
- while ( currentIndex -- > 0 ) {
2219
- currentResult = prependNextStreamItems ( results [ currentIndex ] , {
2220
- streamRecord,
2221
- result : currentResult ,
2222
- } ) ;
2218
+ if ( ! erroredSynchronously ) {
2219
+ currentStreamItems . result = prependNextStreamItems (
2220
+ currentStreamItems . result ,
2221
+ { streamRecord, result : { streamRecord } } ,
2222
+ ) ;
2223
2223
}
2224
2224
2225
- return currentResult ;
2225
+ return firstStreamItems . result ;
2226
2226
} ) ,
2227
2227
} ;
2228
- return firstStreamItems ;
2229
2228
}
2230
2229
2231
2230
function prependNextStreamItems (
0 commit comments