From 352db54f02b5395e7c5c8f08f4520a03cf498c75 Mon Sep 17 00:00:00 2001 From: Kien Dang Date: Sun, 29 Oct 2023 12:11:55 +0800 Subject: [PATCH] Remove duplicated operation_ast not None check --- graphene_django/views.py | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/graphene_django/views.py b/graphene_django/views.py index c095a35..9fc6172 100644 --- a/graphene_django/views.py +++ b/graphene_django/views.py @@ -19,7 +19,6 @@ from graphql import ( ) from graphql.error import GraphQLError from graphql.execution.middleware import MiddlewareManager -from graphql.language import OperationDefinitionNode from graphql.validation import validate from graphene import Schema @@ -316,27 +315,9 @@ class GraphQLView(View): 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 ( request.method.lower() == "get" + and operation_ast is not None and operation_ast.operation != OperationType.QUERY ): if show_graphiql: @@ -370,9 +351,13 @@ class GraphQLView(View): ] = self.execution_context_class if ( - graphene_settings.ATOMIC_MUTATIONS is True - or connection.settings_dict.get("ATOMIC_MUTATIONS", False) is True - ) and operation_ast.operation == OperationType.MUTATION: + operation_ast is not None + 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(): result = execute(schema, document, **execute_options) if getattr(request, MUTATION_ERRORS_FLAG, False) is True: