ash_graphql icon indicating copy to clipboard operation
ash_graphql copied to clipboard

errors do not conform to the GraphQL specification

Open oliverpool opened this issue 1 year ago • 1 comments

Describe the bug

According to the end of 7.1.2 Errors, non-standard fields should be put under extensions in case of error.

Currently when returning an error, this extension behaves like the counter example and sets code, fields, short_message and vars directly:

{
  "data": null,
  "errors": [
    {
      "code": "forbidden",
      "fields": [],
      "locations": [{ "column": 3, "line": 2 }],
      "message": "forbidden",
      "path": ["some_path"],
      "short_message": "forbidden",
      "vars": {}
    }
  ]
}

To Reproduce Setup a GraphQL server and perform a request which triggers an authentication failure.

Expected behavior The non-standard fields should be put under an extensions key:

{
  "data": null,
  "errors": [
    {
      "locations": [{ "column": 3, "line": 2 }],
      "message": "forbidden",
      "path": ["some_path"],
      "extensions": {
        "code": "forbidden",
        "fields": [],
        "short_message": "forbidden",
        "vars": {}
      }
    }
  ]
}

To not break backward compatibility while providing support for spec-compliant clients, the fields could be duplicated in the meantime:

{
  "data": null,
  "errors": [
    {
      "locations": [{ "column": 3, "line": 2 }],
      "message": "forbidden",
      "path": ["some_path"],

      "code": "forbidden",
      "fields": [],
      "short_message": "forbidden",
      "vars": {}
      "extensions": {
        "code": "forbidden",
        "fields": [],
        "short_message": "forbidden",
        "vars": {}
      }
    }
  ]
}

Additional context I am querying the GraphQL server with a Go client which discards non-standard keys not put under extensions: https://pkg.go.dev/github.com/vektah/gqlparser/[email protected]/gqlerror#Error

oliverpool avatar Oct 03 '24 13:10 oliverpool

Thanks for the report! There is no harm in adding it to both places. I won't have time to do this in the near future, but PRs welcome 🙇

zachdaniel avatar Oct 03 '24 16:10 zachdaniel