ash_graphql
ash_graphql copied to clipboard
errors do not conform to the GraphQL specification
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
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 🙇