sandorbedo
Hi,
How should an Absinthe.Resolution struct look like when I want to return both data and errors from Absinthe?
This is now allowed by the GraphQL spec., but whenever I put something into the errors field of the Absinthe.Resolution struct, the data part of the response disappears from the response. This is what I try to do in a middleware without much success:
def call(resolution, params) do
resolution
|> Absinthe.Resolution.put_result({:error, params.errors})
|> Absinthe.Resolution.put_result({:ok, params.data})
end
…and in the handler function I simply return {:middleware, MyMiddleware, %{data: ..., errors: ...}}. It doesn’t make any difference when I try to manipulate the resolution struct directly, not via put_result/2.
What’s wrong with this approach?
Is it even possible to return data and errors in a single response using Absinthe?
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
How Can I Optimise Compile Time Dependencies
I have been building an elixir application for about 2 years now. Many modules and files ha...
New
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #ai
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sandorbedo
I believe this fixes the problem in Absinthe, but I’m not sure why was the result nulled out when there were errors in the response.
benwilson512
It has been a while since I reviewed the spec. For a long time this was not allowed. Can you provide a link to the updated language?
sandorbedo
The relevant section starts here: GraphQL
Here’s an example that shows both data and errors: GraphQL
benwilson512
Hi @sandorbedo this is a common misreading of the spec. This is talking about the overall response shape, not the resolution of any specific field. Absinthe absolutely lets you do the following:
fieldwithNoErrorwill return a result even iffieldWithErrorreturns an error. What you’re asking about is for an individual field to return both data and errors. That’s governed by this section of the spec: Handling Field Errors which unambiguously states:Absinthe is compliant here.
EDIT: A quick check of the 2025 draft shows that this remains unchanged in the latest draft too: GraphQL
sandorbedo
I think the problem is that you interpret “field” as something that has its own resolver, but that field can be part of any object. The object holding the
fieldWithErrorfield has a resolver, but thefieldWithErrorfield itself does not necessarily have one.How should one create a response that looks like this below? (the example is from the GraphQL spec)
The
namefield does not have it’s own resolver in Absinthe, but there is aheroquery that returns an object with ahero_friendsfield, that is a list of friends. Friends haveids andnames, but for some reason we were unable to resolve the name of a certain friend. So, in the resolver of theheroquery we should be able to do something like this:Even if the above
errors: ...syntax would work - which is not the case, this is just an imaginary syntax - the problem is that Absinthe would still return"hero": nullbecause of the current implementation. If we can’t return something like the JSON example above, I don’t understand how can Absinthe be compliant with the spec.benwilson512
To answer your last question first:
You absolutely can:
It’s worth pointing out as well that in your example what is the path of the error? It’s
"path": ["hero", "heroFriends", 1, "name"]. This means that the error was raised while resolving this field. If it was raised from theheroFriendsfield you would see the path simply be["hero", "heroFriends"].This is not correct. Every field has a resolver. Every field is “resolved”. Objects do not have resolvers at all, only fields do. More to the point, the spec is talking about the “process” of resolving a field, which isn’t implementation specific. See GraphQL. Every field goes through this execution and resolution process recursively.