Skip to content

ExecutionResult.formatted does not format errors #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mlorenzana opened this issue Apr 27, 2021 · 5 comments · Fixed by #130
Closed

ExecutionResult.formatted does not format errors #129

mlorenzana opened this issue Apr 27, 2021 · 5 comments · Fixed by #130
Assignees
Labels
bug Something isn't working

Comments

@mlorenzana
Copy link
Contributor

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

@Cito
Copy link
Member

Cito commented Apr 27, 2021

Thanks for reporting. I agree that it would be reasonable to return a list of formatted errors here. Will be fixed.

@Cito Cito self-assigned this Apr 27, 2021
@Cito Cito added the bug Something isn't working label Apr 27, 2021
@AlecRosenbaum
Copy link
Contributor

Wouldn't any tracebacks be attached to the GraphQLError objects under original_error?

@Cito
Copy link
Member

Cito commented Apr 28, 2021

Wouldn't any tracebacks be attached to the GraphQLError objects under original_error?

Not in the formatted result. According to the spec, the formatted error only contains message, locations, path and extensions.

@AlecRosenbaum
Copy link
Contributor

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 at original_error.__traceback__, which would no longer be possible if this was changed.

@Cito
Copy link
Member

Cito commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants