@@ -272,7 +272,6 @@ export function buildExecutionContext(
272
272
fieldResolver: ?GraphQLFieldResolver< mixed , mixed > ,
273
273
typeResolver?: ?GraphQLTypeResolver< mixed , mixed > ,
274
274
): $ReadOnlyArray< GraphQLError > | ExecutionContext {
275
- const errors : Array < GraphQLError > = [ ] ;
276
275
let operation : OperationDefinitionNode | void ;
277
276
let hasMultipleAssumedOperations = false ;
278
277
const fragments : ObjMap < FragmentDefinitionNode > = Object . create ( null ) ;
@@ -297,40 +296,30 @@ export function buildExecutionContext(
297
296
298
297
if ( ! operation ) {
299
298
if ( operationName ) {
300
- errors . push (
301
- new GraphQLError ( `Unknown operation named "${ operationName } ".` ) ,
302
- ) ;
303
- } else {
304
- errors . push ( new GraphQLError ( 'Must provide an operation.' ) ) ;
299
+ return [ new GraphQLError ( `Unknown operation named "${ operationName } ".` ) ] ;
305
300
}
306
- } else if (hasMultipleAssumedOperations) {
307
- errors . push (
301
+ return [ new GraphQLError ( 'Must provide an operation.' ) ] ;
302
+ }
303
+
304
+ if ( hasMultipleAssumedOperations ) {
305
+ return [
308
306
new GraphQLError (
309
307
'Must provide operation name if query contains multiple operations.' ,
310
308
) ,
311
- ) ;
309
+ ] ;
312
310
}
313
311
314
- let variableValues;
315
- if (operation) {
316
- const coercedVariableValues = getVariableValues (
317
- schema ,
318
- operation . variableDefinitions || [ ] ,
319
- rawVariableValues || { } ,
320
- ) ;
321
-
322
- if ( coercedVariableValues . errors ) {
323
- errors . push ( ...coercedVariableValues . errors ) ;
324
- } else {
325
- variableValues = coercedVariableValues . coerced ;
326
- }
327
- }
312
+ const coercedVariableValues = getVariableValues (
313
+ schema ,
314
+ operation . variableDefinitions || [ ] ,
315
+ rawVariableValues || { } ,
316
+ ) ;
328
317
329
- if ( errors . length !== 0 ) {
330
- return errors ;
318
+ if ( coercedVariableValues . errors ) {
319
+ return coercedVariableValues . errors ;
331
320
}
332
321
333
- invariant(operation, 'Has operation if no errors.') ;
322
+ const variableValues = coercedVariableValues.coerced ;
334
323
invariant(variableValues, 'Has variables if no errors.');
335
324
336
325
return {
@@ -342,7 +331,7 @@ export function buildExecutionContext(
342
331
variableValues ,
343
332
fieldResolver : fieldResolver || defaultFieldResolver ,
344
333
typeResolver : typeResolver || defaultTypeResolver ,
345
- errors ,
334
+ errors : [ ] ,
346
335
} ;
347
336
}
348
337
0 commit comments