@@ -157,28 +157,15 @@ export async function createSourceEventStream(
157
157
try {
158
158
const eventStream = await executeSubscription ( exeContext ) ;
159
159
160
- // Assert field returned an event stream, otherwise yield an error.
161
- if ( ! isAsyncIterable ( eventStream ) ) {
162
- throw new Error (
163
- 'Subscription field must return Async Iterable. ' +
164
- `Received: ${ inspect ( eventStream ) } .` ,
165
- ) ;
166
- }
167
-
168
160
return eventStream ;
169
161
} catch ( error ) {
170
- // If it GraphQLError, report it as an ExecutionResult, containing only errors and no data.
171
- // Otherwise treat the error as a system-class error and re-throw it.
172
- if ( error instanceof GraphQLError ) {
173
- return { errors : [ error ] } ;
174
- }
175
- throw error ;
162
+ return { errors : [ error ] } ;
176
163
}
177
164
}
178
165
179
166
async function executeSubscription (
180
167
exeContext : ExecutionContext ,
181
- ) : Promise < unknown > {
168
+ ) : Promise < AsyncIterable < unknown > > {
182
169
const { schema, fragments, operation, variableValues, rootValue } =
183
170
exeContext ;
184
171
@@ -238,6 +225,15 @@ async function executeSubscription(
238
225
if ( eventStream instanceof Error ) {
239
226
throw eventStream ;
240
227
}
228
+
229
+ // Assert field returned an event stream, otherwise yield an error.
230
+ if ( ! isAsyncIterable ( eventStream ) ) {
231
+ throw new GraphQLError (
232
+ 'Subscription field must return Async Iterable. ' +
233
+ `Received: ${ inspect ( eventStream ) } .` ,
234
+ ) ;
235
+ }
236
+
241
237
return eventStream ;
242
238
} catch ( error ) {
243
239
throw locatedError ( error , fieldNodes , pathToArray ( path ) ) ;
0 commit comments