@@ -2163,12 +2163,12 @@ function firstSyncStreamItems(
21632163 info : GraphQLResolveInfo ,
21642164 itemType : GraphQLOutputType ,
21652165) : StreamItemsRecord {
2166- const path = streamRecord . path ;
2167- const initialPath = addPath ( path , initialIndex , undefined ) ;
2168-
2169- const firstStreamItems : StreamItemsRecord = {
2166+ return {
21702167 streamRecord,
21712168 result : Promise . resolve ( ) . then ( ( ) => {
2169+ const path = streamRecord . path ;
2170+ const initialPath = addPath ( path , initialIndex , undefined ) ;
2171+
21722172 let result = completeStreamItems (
21732173 streamRecord ,
21742174 initialPath ,
@@ -2179,7 +2179,8 @@ function firstSyncStreamItems(
21792179 info ,
21802180 itemType ,
21812181 ) ;
2182- const results = [ result ] ;
2182+ const firstStreamItems = { result } ;
2183+ let currentStreamItems = firstStreamItems ;
21832184 let currentIndex = initialIndex ;
21842185 let iteration = iterator . next ( ) ;
21852186 let erroredSynchronously = false ;
@@ -2201,31 +2202,29 @@ function firstSyncStreamItems(
22012202 info ,
22022203 itemType ,
22032204 ) ;
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+
22052213 iteration = iterator . next ( ) ;
22062214 }
22072215
2208- currentIndex = results . length - 1 ;
22092216 // If a non-reconcilable stream items result was encountered, then the stream terminates in error.
22102217 // 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+ ) ;
22232223 }
22242224
2225- return currentResult ;
2225+ return firstStreamItems . result ;
22262226 } ) ,
22272227 } ;
2228- return firstStreamItems ;
22292228}
22302229
22312230function prependNextStreamItems (
0 commit comments