@@ -2081,16 +2081,61 @@ async function executeStreamIterator(
2081
2081
2082
2082
let iteration ;
2083
2083
try {
2084
- // eslint-disable-next-line no-await-in-loop
2085
- iteration = await executeStreamIteratorItem (
2086
- iterator ,
2087
- exeContext ,
2088
- fieldNodes ,
2089
- info ,
2090
- itemType ,
2091
- asyncPayloadRecord ,
2092
- itemPath ,
2093
- ) ;
2084
+ try {
2085
+ // eslint-disable-next-line no-await-in-loop
2086
+ const { value, done } = await iterator . next ( ) ;
2087
+ if ( done ) {
2088
+ asyncPayloadRecord . setIsCompletedIterator ( ) ;
2089
+ iteration = { done, value : undefined } ;
2090
+ } else {
2091
+ let completedItem ;
2092
+ try {
2093
+ completedItem = completeValue (
2094
+ exeContext ,
2095
+ itemType ,
2096
+ fieldNodes ,
2097
+ info ,
2098
+ itemPath ,
2099
+ value ,
2100
+ asyncPayloadRecord ,
2101
+ ) ;
2102
+
2103
+ if ( isPromise ( completedItem ) ) {
2104
+ completedItem = handleAsyncCompletionError (
2105
+ completedItem ,
2106
+ exeContext ,
2107
+ itemType ,
2108
+ fieldNodes ,
2109
+ itemPath ,
2110
+ asyncPayloadRecord ,
2111
+ ) ;
2112
+ }
2113
+ iteration = { done : false , value : completedItem } ;
2114
+ } catch ( rawError ) {
2115
+ const error = locatedError (
2116
+ rawError ,
2117
+ fieldNodes ,
2118
+ pathToArray ( itemPath ) ,
2119
+ ) ;
2120
+ const handledError = handleFieldError (
2121
+ error ,
2122
+ itemType ,
2123
+ asyncPayloadRecord . errors ,
2124
+ ) ;
2125
+ filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
2126
+ iteration = { done : false , value : handledError } ;
2127
+ }
2128
+ }
2129
+ } catch ( rawError ) {
2130
+ const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
2131
+ const handledError = handleFieldError (
2132
+ error ,
2133
+ itemType ,
2134
+ asyncPayloadRecord . errors ,
2135
+ ) ;
2136
+ // don't continue if iterator throws
2137
+ iteration = { done : true , value : handledError } ;
2138
+ }
2094
2139
} catch ( error ) {
2095
2140
asyncPayloadRecord . errors . push ( error ) ;
2096
2141
filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
@@ -2132,60 +2177,6 @@ async function executeStreamIterator(
2132
2177
}
2133
2178
}
2134
2179
2135
- async function executeStreamIteratorItem (
2136
- iterator : AsyncIterator < unknown > ,
2137
- exeContext : ExecutionContext ,
2138
- fieldNodes : ReadonlyArray < FieldNode > ,
2139
- info : GraphQLResolveInfo ,
2140
- itemType : GraphQLOutputType ,
2141
- asyncPayloadRecord : StreamRecord ,
2142
- itemPath : Path ,
2143
- ) : Promise < IteratorResult < unknown > > {
2144
- let item ;
2145
- try {
2146
- const { value, done } = await iterator . next ( ) ;
2147
- if ( done ) {
2148
- asyncPayloadRecord . setIsCompletedIterator ( ) ;
2149
- return { done, value : undefined } ;
2150
- }
2151
- item = value ;
2152
- } catch ( rawError ) {
2153
- const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
2154
- const value = handleFieldError ( error , itemType , asyncPayloadRecord . errors ) ;
2155
- // don't continue if iterator throws
2156
- return { done : true , value } ;
2157
- }
2158
- let completedItem ;
2159
- try {
2160
- completedItem = completeValue (
2161
- exeContext ,
2162
- itemType ,
2163
- fieldNodes ,
2164
- info ,
2165
- itemPath ,
2166
- item ,
2167
- asyncPayloadRecord ,
2168
- ) ;
2169
-
2170
- if ( isPromise ( completedItem ) ) {
2171
- completedItem = handleAsyncCompletionError (
2172
- completedItem ,
2173
- exeContext ,
2174
- itemType ,
2175
- fieldNodes ,
2176
- itemPath ,
2177
- asyncPayloadRecord ,
2178
- ) ;
2179
- }
2180
- return { done : false , value : completedItem } ;
2181
- } catch ( rawError ) {
2182
- const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
2183
- const value = handleFieldError ( error , itemType , asyncPayloadRecord . errors ) ;
2184
- filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
2185
- return { done : false , value } ;
2186
- }
2187
- }
2188
-
2189
2180
function filterSubsequentPayloads (
2190
2181
exeContext : ExecutionContext ,
2191
2182
nullPath : Path ,
0 commit comments