Closed
Description
When I call formatted on an ExecutionResult, the errors portion of the dict is not formatted and instead returns a list of GraphQLErrors. GraphQLError is not serializable, but it does have a formatted property which is, why is formatted not called on the list of GraphQLErrors?
As a work around, I have to call formatted on my ExecutionResult and then rebuild the dict and format the errors:
formatted = result.formatted
data = formatted.get('data')
errors = ([err.formatted for err in formatted.get('errors')]
if formatted.get('errors') is not None
else None)
extensions = formatted.get('extensions')
if extensions:
body = dict(data=data, errors=errors, extensions=extensions)
else:
body = dict(data=data, errors=errors)
Ideally ExecutionResult.formatted would perform this error formatting for me.
Environment:
python 3.8
graphql-core 3.1.4
Activity
Cito commentedon Apr 27, 2021
Thanks for reporting. I agree that it would be reasonable to return a list of formatted errors here. Will be fixed.
AlecRosenbaum commentedon Apr 27, 2021
Wouldn't any tracebacks be attached to the
GraphQLError
objects underoriginal_error
?Cito commentedon Apr 28, 2021
Not in the formatted result. According to the spec, the formatted error only contains message, locations, path and extensions.
AlecRosenbaum commentedon Apr 28, 2021
Right, sorry let me rephrase.
If
GraphQLError
's are automatically formatted when being put into the result, is there any way of accessing traceback data? I had thought the accepted way was by looking atoriginal_error.__traceback__
, which would no longer be possible if this was changed.Cito commentedon Apr 28, 2021
Don't worry. The execution results and errors are not automatically formatted. We're only talking about the case when you access the
formatted
property of these objects. With other words, if you access the errors of the execution result, they will be still a list of GraphQLErrors, if you access the errors of the formatted execution result, they will be a list of formatted GraphQLErrors.Return formatted errors in formatted execution result (fixes #129)