Skip to content
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

SourceLocation should be serialized as object #61

Closed
ktosiek opened this issue Sep 15, 2019 · 2 comments
Closed

SourceLocation should be serialized as object #61

ktosiek opened this issue Sep 15, 2019 · 2 comments

Comments

@ktosiek
Copy link
Contributor

ktosiek commented Sep 15, 2019

SourceLocation, as a NamedTuple, is serialized by json.dumps() to an array instead of an object. Graphql.js keeps SourceLocation as and object, so it just works for them.

Reproduction:

from graphql import SourceLocation, GraphQLError, format_error, Source
import json

print(json.dumps(format_error(GraphQLError(message="test", source=Source('{ test }'), positions=[2]))))

Expected result: {"message": "test", "locations": [{"line": 1, "column": 3}], "path": null}
Actual result: {"message": "test", "locations": [[1, 3]], "path": null}

Should SourceLocation be changed to something that serializes correctly? Or would it make more sense to convert it to dict in format_errors?

ktosiek added a commit to ktosiek/graphene-django that referenced this issue Sep 15, 2019
Some of the tests show the problem described here: graphql-python/graphql-core#61
ktosiek added a commit to ktosiek/graphene-django that referenced this issue Sep 16, 2019
Some of the tests show the problem described here: graphql-python/graphql-core#61
@Cito
Copy link
Member

Cito commented Sep 16, 2019

Good point. Yes, I think it makes totally sense to return locations as a list of dicts in format_error - that's why we have this function. Feel free to send a PR, or otherwise I can change this.

@Cito
Copy link
Member

Cito commented Sep 26, 2019

This is now included in v3.0.0b1.

@Cito Cito closed this as completed Sep 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants