Skip to content

SourceLocation should be serialized as object #61

Closed
@ktosiek

Description

@ktosiek

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions