@@ -174,34 +174,7 @@ export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
174
174
return { errors : exeContext } ;
175
175
}
176
176
177
- // Return a Promise that will eventually resolve to the data described by
178
- // The "Response" section of the GraphQL specification.
179
- //
180
- // If errors are encountered while executing a GraphQL field, only that
181
- // field and its descendants will be omitted, and sibling fields will still
182
- // be executed. An execution which encounters errors will still result in a
183
- // resolved Promise.
184
- //
185
- // Errors from sub-fields of a NonNull type may propagate to the top level,
186
- // at which point we still log the error and null the parent field, which
187
- // in this case is the entire response.
188
- try {
189
- const { operation } = exeContext ;
190
- const result = executeOperation ( exeContext , operation ) ;
191
- if ( isPromise ( result ) ) {
192
- return result . then (
193
- ( data ) => buildResponse ( data , exeContext . errors ) ,
194
- ( error ) => {
195
- exeContext . errors . push ( error ) ;
196
- return buildResponse ( null , exeContext . errors ) ;
197
- } ,
198
- ) ;
199
- }
200
- return buildResponse ( result , exeContext . errors ) ;
201
- } catch ( error ) {
202
- exeContext . errors . push ( error ) ;
203
- return buildResponse ( null , exeContext . errors ) ;
204
- }
177
+ return executeOperation ( exeContext , exeContext . operation ) ;
205
178
}
206
179
207
180
/**
@@ -330,12 +303,14 @@ export function buildExecutionContext(
330
303
function executeOperation (
331
304
exeContext : ExecutionContext ,
332
305
operation : OperationDefinitionNode ,
333
- ) : PromiseOrValue < ObjMap < unknown > > {
306
+ ) : PromiseOrValue < ExecutionResult > {
334
307
const rootType = exeContext . schema . getRootType ( operation . operation ) ;
335
308
if ( rootType == null ) {
336
- throw new GraphQLError (
337
- `Schema is not configured to execute ${ operation . operation } operation.` ,
338
- { nodes : operation } ,
309
+ return buildErrorResponse (
310
+ new GraphQLError (
311
+ `Schema is not configured to execute ${ operation . operation } operation.` ,
312
+ { nodes : operation } ,
313
+ ) ,
339
314
) ;
340
315
}
341
316
@@ -364,13 +339,40 @@ function executeRootFields(
364
339
rootType : GraphQLObjectType ,
365
340
rootFields : Map < string , ReadonlyArray < FieldNode > > ,
366
341
executeSerially : boolean ,
367
- ) : PromiseOrValue < ObjMap < unknown > > {
342
+ ) : PromiseOrValue < ExecutionResult > {
368
343
const { rootValue } = exeContext ;
369
344
const path = undefined ;
370
345
371
- return executeSerially
372
- ? executeFieldsSerially ( exeContext , rootType , rootValue , path , rootFields )
373
- : executeFields ( exeContext , rootType , rootValue , path , rootFields ) ;
346
+ // Return a Promise that will eventually resolve to the data described by
347
+ // The "Response" section of the GraphQL specification.
348
+ //
349
+ // If errors are encountered while executing a GraphQL field, only that
350
+ // field and its descendants will be omitted, and sibling fields will still
351
+ // be executed. An execution which encounters errors will still result in a
352
+ // resolved Promise.
353
+ //
354
+ // Errors from sub-fields of a NonNull type may propagate to the top level,
355
+ // at which point we still log the error and null the parent field, which
356
+ // in this case is the entire response.
357
+ try {
358
+ const data = executeSerially
359
+ ? executeFieldsSerially ( exeContext , rootType , rootValue , path , rootFields )
360
+ : executeFields ( exeContext , rootType , rootValue , path , rootFields ) ;
361
+
362
+ if ( isPromise ( data ) ) {
363
+ return data . then (
364
+ ( resolvedData ) => buildResponse ( resolvedData , exeContext . errors ) ,
365
+ ( error ) => {
366
+ exeContext . errors . push ( error ) ;
367
+ return buildResponse ( null , exeContext . errors ) ;
368
+ } ,
369
+ ) ;
370
+ }
371
+ return buildResponse ( data , exeContext . errors ) ;
372
+ } catch ( error ) {
373
+ exeContext . errors . push ( error ) ;
374
+ return { errors : exeContext . errors , data : null } ;
375
+ }
374
376
}
375
377
376
378
/**
0 commit comments