Skip to content

ExecutionResult.formatted does not format errors #129

Closed
@mlorenzana

Description

@mlorenzana

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

Cito commented on Apr 27, 2021

@Cito
Member

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

self-assigned this
on Apr 27, 2021
added
bugSomething isn't working
on Apr 27, 2021
AlecRosenbaum

AlecRosenbaum commented on Apr 27, 2021

@AlecRosenbaum
Contributor

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

Cito

Cito commented on Apr 28, 2021

@Cito
Member

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

AlecRosenbaum commented on Apr 28, 2021

@AlecRosenbaum
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

Cito commented on Apr 28, 2021

@Cito
Member

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.

added a commit that references this issue on Apr 28, 2021
8d71342
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    ExecutionResult.formatted does not format errors · Issue #129 · graphql-python/graphql-core