Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 12, 2024
1 parent 29532a6 commit d9ad3da
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 41 deletions.
79 changes: 39 additions & 40 deletions strawberry/schema/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -299,4 +298,4 @@ def execute_sync(
)


__all__ = ["execute", "execute_sync"]
__all__ = ["execute", "execute_sync"]
3 changes: 2 additions & 1 deletion tests/schema/extensions/test_mask_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def hidden_error(self) -> str:
]



async def test_mask_all_errors_async():
@strawberry.type
class Query:
Expand All @@ -51,6 +50,8 @@ def hidden_error(self) -> str:
"path": ["hiddenError"],
}
]


def test_mask_some_errors():
class VisibleError(Exception):
pass
Expand Down

0 comments on commit d9ad3da

Please sign in to comment.