From d9ad3daa0db78e54762277c32c462f768589a839 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 12 Sep 2024 18:06:37 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strawberry/schema/execute.py | 79 ++++++++++----------- tests/schema/extensions/test_mask_errors.py | 3 +- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/strawberry/schema/execute.py b/strawberry/schema/execute.py index 904b523bce..c9fa4953b7 100644 --- a/strawberry/schema/execute.py +++ b/strawberry/schema/execute.py @@ -156,52 +156,51 @@ async def execute( middleware_manager: MiddlewareManager, execution_context_class: Optional[Type[GraphQLExecutionContext]] = None, ) -> ExecutionResult | PreExecutionError: - async with extensions_runner.operation(): - try: - - # Note: In graphql-core the schema would be validated here but in - # Strawberry we are validating it at initialisation time instead + async with extensions_runner.operation(): + try: + # Note: In graphql-core the schema would be validated here but in + # Strawberry we are validating it at initialisation time instead - if errors := await _parse_and_validate_async( - execution_context, extensions_runner - ): - return await _handle_execution_result( - execution_context, errors, extensions_runner, process_errors - ) + if errors := await _parse_and_validate_async( + execution_context, extensions_runner + ): + return await _handle_execution_result( + execution_context, errors, extensions_runner, process_errors + ) - assert execution_context.graphql_document - async with extensions_runner.executing(): - if not execution_context.result: - result = await await_maybe( - original_execute( - schema, - execution_context.graphql_document, - root_value=execution_context.root_value, - middleware=middleware_manager, - variable_values=execution_context.variables, - operation_name=execution_context.operation_name, - context_value=execution_context.context, - execution_context_class=execution_context_class, - ) + assert execution_context.graphql_document + async with extensions_runner.executing(): + if not execution_context.result: + result = await await_maybe( + original_execute( + schema, + execution_context.graphql_document, + root_value=execution_context.root_value, + middleware=middleware_manager, + variable_values=execution_context.variables, + operation_name=execution_context.operation_name, + context_value=execution_context.context, + execution_context_class=execution_context_class, ) + ) - else: - result = execution_context.result - + else: + result = execution_context.result - except (MissingQueryError, InvalidOperationTypeError) as e: - raise e - except Exception as exc: - return await _handle_execution_result( - execution_context, - PreExecutionError(data=None, errors=[_coerce_error(exc)]), - extensions_runner, - process_errors, - ) - # return results after all the operation completed. + except (MissingQueryError, InvalidOperationTypeError) as e: + raise e + except Exception as exc: return await _handle_execution_result( - execution_context, result, extensions_runner, process_errors + execution_context, + PreExecutionError(data=None, errors=[_coerce_error(exc)]), + extensions_runner, + process_errors, ) + # return results after all the operation completed. + return await _handle_execution_result( + execution_context, result, extensions_runner, process_errors + ) + def execute_sync( schema: GraphQLSchema, @@ -299,4 +298,4 @@ def execute_sync( ) -__all__ = ["execute", "execute_sync"] \ No newline at end of file +__all__ = ["execute", "execute_sync"] diff --git a/tests/schema/extensions/test_mask_errors.py b/tests/schema/extensions/test_mask_errors.py index d6cf0f908e..58ef32c28e 100644 --- a/tests/schema/extensions/test_mask_errors.py +++ b/tests/schema/extensions/test_mask_errors.py @@ -29,7 +29,6 @@ def hidden_error(self) -> str: ] - async def test_mask_all_errors_async(): @strawberry.type class Query: @@ -51,6 +50,8 @@ def hidden_error(self) -> str: "path": ["hiddenError"], } ] + + def test_mask_some_errors(): class VisibleError(Exception): pass