Skip to content

SourceLocation should be serialized as object #61

Closed

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?

Activity

  1. Cito commented on Sep 16, 2019

    @Cito
    Member

    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.

  2. Cito commented on Sep 26, 2019

    @Cito
    Member

    This is now included in v3.0.0b1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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