@@ -279,17 +279,20 @@ export function buildExecutionContext(
279
279
typeResolver?: ?GraphQLTypeResolver< mixed , mixed > ,
280
280
): $ReadOnlyArray< GraphQLError > | ExecutionContext {
281
281
let operation : OperationDefinitionNode | void ;
282
- let hasMultipleAssumedOperations = false ;
283
282
const fragments : ObjMap < FragmentDefinitionNode > = Object . create ( null ) ;
284
283
for ( const definition of document . definitions ) {
285
284
switch ( definition . kind ) {
286
285
case Kind . OPERATION_DEFINITION :
287
- if ( ! operationName && operation ) {
288
- hasMultipleAssumedOperations = true ;
289
- } else if (
290
- ! operationName ||
291
- ( definition . name && definition . name . value === operationName )
292
- ) {
286
+ if ( operationName == null ) {
287
+ if ( operation !== undefined ) {
288
+ return [
289
+ new GraphQLError (
290
+ 'Must provide operation name if query contains multiple operations.' ,
291
+ ) ,
292
+ ] ;
293
+ }
294
+ operation = definition ;
295
+ } else if ( definition . name && definition . name . value === operationName ) {
293
296
operation = definition ;
294
297
}
295
298
break ;
@@ -300,20 +303,12 @@ export function buildExecutionContext(
300
303
}
301
304
302
305
if ( ! operation ) {
303
- if ( operationName ) {
306
+ if ( operationName != null ) {
304
307
return [ new GraphQLError ( `Unknown operation named "${ operationName } ".` ) ] ;
305
308
}
306
309
return [new GraphQLError('Must provide an operation.')];
307
310
}
308
311
309
- if ( hasMultipleAssumedOperations ) {
310
- return [
311
- new GraphQLError (
312
- 'Must provide operation name if query contains multiple operations.' ,
313
- ) ,
314
- ] ;
315
- }
316
-
317
312
const coercedVariableValues = getVariableValues (
318
313
schema ,
319
314
operation . variableDefinitions || [ ] ,
0 commit comments