Skip to content

Commit bec2191

Browse files
committed
Make UnforgivingExecutionContext work with graphql-core 3.1.5
1 parent 485b1ed commit bec2191

File tree

1 file changed

+7
-88
lines changed

1 file changed

+7
-88
lines changed

graphene/types/schema.py

Lines changed: 7 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -396,96 +396,15 @@ def resolve_type(self, resolve_type_func, type_name, root, info, _type):
396396
class UnforgivingExecutionContext(ExecutionContext):
397397
"""An execution context which doesn't swallow exceptions.
398398
399-
The only difference between this execution context and the one it inherits from is
400-
that ``except Exception`` is commented out within ``resolve_field_value_or_error``.
401-
By removing that exception handling, only ``GraphQLError``'s are caught.
399+
Instead it re-raise the original error
402400
"""
403401

404-
def resolve_field_value_or_error(
405-
self, field_def, field_nodes, resolve_fn, source, info
406-
):
407-
"""Resolve field to a value or an error.
408-
409-
Isolates the "ReturnOrAbrupt" behavior to not de-opt the resolve_field()
410-
method. Returns the result of resolveFn or the abrupt-return Error object.
411-
412-
For internal use only.
413-
"""
414-
try:
415-
# Build a dictionary of arguments from the field.arguments AST, using the
416-
# variables scope to fulfill any variable references.
417-
args = get_argument_values(field_def, field_nodes[0], self.variable_values)
418-
419-
# Note that contrary to the JavaScript implementation, we pass the context
420-
# value as part of the resolve info.
421-
result = resolve_fn(source, info, **args)
422-
if self.is_awaitable(result):
423-
# noinspection PyShadowingNames
424-
async def await_result():
425-
try:
426-
return await result
427-
except GraphQLError as error:
428-
return error
429-
# except Exception as error:
430-
# return GraphQLError(str(error), original_error=error)
431-
432-
# Yes, this is commented out code. It's been intentionally
433-
# _not_ removed to show what has changed from the original
434-
# implementation.
435-
436-
return await_result()
437-
return result
438-
except GraphQLError as error:
439-
return error
440-
# except Exception as error:
441-
# return GraphQLError(str(error), original_error=error)
442-
443-
# Yes, this is commented out code. It's been intentionally _not_
444-
# removed to show what has changed from the original implementation.
445-
446-
def complete_value_catching_error(
447-
self, return_type, field_nodes, info, path, result
448-
):
449-
"""Complete a value while catching an error.
450-
451-
This is a small wrapper around completeValue which detects and logs errors in
452-
the execution context.
453-
"""
454-
try:
455-
if self.is_awaitable(result):
456-
457-
async def await_result():
458-
value = self.complete_value(
459-
return_type, field_nodes, info, path, await result
460-
)
461-
if self.is_awaitable(value):
462-
return await value
463-
return value
464-
465-
completed = await_result()
466-
else:
467-
completed = self.complete_value(
468-
return_type, field_nodes, info, path, result
469-
)
470-
if self.is_awaitable(completed):
471-
# noinspection PyShadowingNames
472-
async def await_completed():
473-
try:
474-
return await completed
475-
476-
# CHANGE WAS MADE HERE
477-
# ``GraphQLError`` was swapped in for ``except Exception``
478-
except GraphQLError as error:
479-
self.handle_field_error(error, field_nodes, path, return_type)
480-
481-
return await_completed()
482-
return completed
483-
484-
# CHANGE WAS MADE HERE
485-
# ``GraphQLError`` was swapped in for ``except Exception``
486-
except GraphQLError as error:
487-
self.handle_field_error(error, field_nodes, path, return_type)
488-
return None
402+
def handle_field_error(
403+
self,
404+
error: GraphQLError,
405+
return_type,
406+
) -> None:
407+
raise error.original_error
489408

490409

491410
class Schema:

0 commit comments

Comments
 (0)