mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-10 16:22:20 +03:00
Remove duplicated operation_ast not None check
This commit is contained in:
parent
2e4c6a25dc
commit
352db54f02
|
@ -19,7 +19,6 @@ from graphql import (
|
||||||
)
|
)
|
||||||
from graphql.error import GraphQLError
|
from graphql.error import GraphQLError
|
||||||
from graphql.execution.middleware import MiddlewareManager
|
from graphql.execution.middleware import MiddlewareManager
|
||||||
from graphql.language import OperationDefinitionNode
|
|
||||||
from graphql.validation import validate
|
from graphql.validation import validate
|
||||||
|
|
||||||
from graphene import Schema
|
from graphene import Schema
|
||||||
|
@ -316,27 +315,9 @@ class GraphQLView(View):
|
||||||
|
|
||||||
operation_ast = get_operation_ast(document, operation_name)
|
operation_ast = get_operation_ast(document, operation_name)
|
||||||
|
|
||||||
if not operation_ast:
|
|
||||||
ops_count = len(
|
|
||||||
[
|
|
||||||
x
|
|
||||||
for x in document.definitions
|
|
||||||
if isinstance(x, OperationDefinitionNode)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
if ops_count > 1:
|
|
||||||
op_error = (
|
|
||||||
"Must provide operation name if query contains multiple operations."
|
|
||||||
)
|
|
||||||
elif operation_name:
|
|
||||||
op_error = f"Unknown operation named '{operation_name}'."
|
|
||||||
else:
|
|
||||||
op_error = "Must provide a valid operation."
|
|
||||||
|
|
||||||
return ExecutionResult(errors=[GraphQLError(op_error)])
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
request.method.lower() == "get"
|
request.method.lower() == "get"
|
||||||
|
and operation_ast is not None
|
||||||
and operation_ast.operation != OperationType.QUERY
|
and operation_ast.operation != OperationType.QUERY
|
||||||
):
|
):
|
||||||
if show_graphiql:
|
if show_graphiql:
|
||||||
|
@ -370,9 +351,13 @@ class GraphQLView(View):
|
||||||
] = self.execution_context_class
|
] = self.execution_context_class
|
||||||
|
|
||||||
if (
|
if (
|
||||||
graphene_settings.ATOMIC_MUTATIONS is True
|
operation_ast is not None
|
||||||
or connection.settings_dict.get("ATOMIC_MUTATIONS", False) is True
|
and operation_ast.operation == OperationType.MUTATION
|
||||||
) and operation_ast.operation == OperationType.MUTATION:
|
and (
|
||||||
|
graphene_settings.ATOMIC_MUTATIONS is True
|
||||||
|
or connection.settings_dict.get("ATOMIC_MUTATIONS", False) is True
|
||||||
|
)
|
||||||
|
):
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
result = execute(schema, document, **execute_options)
|
result = execute(schema, document, **execute_options)
|
||||||
if getattr(request, MUTATION_ERRORS_FLAG, False) is True:
|
if getattr(request, MUTATION_ERRORS_FLAG, False) is True:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user