Skip to content

Commit 861c50a

Browse files
committed
More detailed invalid operation error message
1 parent 168ef1f commit 861c50a

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

Diff for: graphene_django/views.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from graphql import ExecutionResult, OperationType, execute, get_operation_ast, parse
1313
from graphql.error import GraphQLError
1414
from graphql.execution.middleware import MiddlewareManager
15+
from graphql.language import OperationDefinitionNode
1516
from graphql.validation import validate
1617

1718
from graphene import Schema
@@ -302,7 +303,21 @@ def execute_graphql_request(
302303

303304
op_error = None
304305
if not operation_ast:
305-
op_error = "Must provide a valid operation."
306+
ops_count = len(
307+
[
308+
x
309+
for x in document.definitions
310+
if isinstance(x, OperationDefinitionNode)
311+
]
312+
)
313+
if ops_count > 1:
314+
op_error = (
315+
"Must provide operation name if query contains multiple operations"
316+
)
317+
elif operation_name:
318+
op_error = f"Unknown operation named '{operation_name}'."
319+
else:
320+
op_error = "Must provide a valid operation."
306321
elif operation_ast.operation == OperationType.SUBSCRIPTION:
307322
op_error = "The 'subscription' operation is not supported."
308323

0 commit comments

Comments
 (0)