michaelcaterisano
Unable to return errors when List [T] contains null values
I’m trying to do the same thing described in this issue: Allow returning data and errors from a resolver · Issue #512 · absinthe-graphql/absinthe · GitHub
That is, I want to create a mutation field whose return type looks like this:
type MutationPayload {
entities: [Entity]
}
And handle partial success with a response like this:
{
data: {
createEntities: {
entities: [ {text: "hi"}, null, {text: "hello"} ]
}
},
errors: [{ message: "some error related to entity with id 123" }]
}
In the linked issue above, @benwilson512 says that this response is not allowed by the spec. I’ve been discussing this subject with my team, and there is some doubt about this interpretation. I think it’s informed by the Response section of the spec, specifically this paragraph:If an error was encountered during the execution that prevented a valid response, the data entry in the response should be null.
However, the List section seems to suggest that the response described above is in fact valid: If a list’s item type is nullable, then errors occuring during preparation or coercion of an individual item in the list must result in a the value null at that position in the list along with an error added to the response.
The Absinthe library disallows this response, as described in the github issue. I can confirm that this is the case. Do folks have any thoughts about how to approach this? It seems to me that the library isn’t allowing something that should be allowed by the spec, and I’m hoping to find a workaround.
Most Liked
benwilson512
Just to be clear, my solution returns errors as errors to the client, not as data. It is returning errors as part of the Elixir resolver return value sure, but then it’s converted to a GraphQL error here:
field :entity, :entity, resolve fn
%{entity: entity}, _, _ -> {:ok, entity}
%{error: error}, _, _ -> error
end
Notice how in the mutation resolver result item at index 1 is %{error: {:error, "reason"}} and so the value is unpacked from the %{error: key it means that the resolver is returning {:error, "reason"} which means you get a proper GraphQL error.
That is the question, and they definitely are not, nor is “coercion” or “preparation” the same as resolution or execution. If you read through the “Executing fields” section GraphQL I think it’s pretty clear that a given item in a list cannot also be a field. It doesn’t take arguments, it doesn’t have a distinct selection set, etc.
The other thing to emphasize is that we’re talking about the resolution of a specific mutation field. That field has a single return value. That value can be a list type, but that list type is not then N resolutions, where there is a distinct resolution for each item in the list. Rather there is one resolution (the resolution of the mutation field) that returns one value (a list), there is a “result coercion” of that value, which involves a result coercion of each item in the list. Then fields in the selection set on the result are executed on each result. There is no field that represents individual item from parent list -> individual item | null | errors, nor is there a resolver for such.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








