graphql
graphql copied to clipboard
Expose details for returned errors
Exposes the error as graphql.Error
and returns error details in case they are present in the error response.
The user should assert the error type:
err := cli.Run(...)
if errs, ok := err.(graphql.Errors); ok {
// Range over errs
}
// or with go 1.13
var errs graphql.Errors
if errors.As(err, errs) {
// Range over errs
}
Included:
-
message
: As before -
locations
: Locations in the query that caused errors -
paths
: Response paths that returned errors -
extensions
: Optional extensions set by the server. The spec specified it's a map but nothing more.
The format matches the June 2018 spec for errors: https://graphql.github.io/graphql-spec/June2018/#sec-Errors
This PR is very similar to some previous ones:
- https://github.com/machinebox/graphql/pull/24, https://github.com/machinebox/graphql/pull/34 - Slightly different way of accessing extensions (
map[string]interface{}
instead of method) + includes locations and path - https://github.com/machinebox/graphql/pull/37 - This PR also prints multiple returned errors (slightly different format) and also allows inspecting the errors for additional values (locations, path, extensions)
Could we get some love on this to get merged? It would be great to have better visibility into errors using this lib.
Is there anything blocking this PR from getting merged? (or #24)