The GraphQL Spec provides information on how errors should be structured, which includes the message, locations, and path keys. The spec then states that anything additional should be nested under an extensions key rather than added at the top level, the reasoning being that future revisions to the spec may add additional keys that could conflict with any custom data.
Right now errors seem to be processed in this way:
{:error, message: "bad request", something: "something"}%Phase.Error{} struct with all of the keys other than message being pushed into a nested extra field: {:error, message: "bad request", extra: %{something: "something"}}Absinthe.Phase.Document.Result.format_error/1 later merges the extra key back into the top level.%{errors: [%{message: "bad request", something: "something"}]. In the mean time I can get around this by having my resolvers explicitly nest my extra info under an extensions key.
I'm not sure if this is something that should be changed in Absinthe to match the spec, or if we just need to update the Errors documentation to state that extra info should be in an extensions key.
Based on the spec, I would expect the errors to be returned as:
%{
errors: [
%{
message: "bad request",
extensions: %{
something: "something"
}
}
]
}
The errors are returned as:
%{
errors: [
%{
message: "bad request",
something: "something"
}
]
}
Hi @dmarkow good catch. This behaviour exists from before extensions were part of the GraphQL spec. I'm fine aiming to change this in 1.6, with the aim to create some kind of warning in a 1.5.x release.
Most helpful comment
Hi @dmarkow good catch. This behaviour exists from before extensions were part of the GraphQL spec. I'm fine aiming to change this in 1.6, with the aim to create some kind of warning in a 1.5.x release.