sandorbedo
Hi,
Let’s say I have a GraphQL schema like this:
type Ops {
add(a: Int, b: Int): Int
}
type Query {
calc: Ops
}
…and I want my Absinthe server to answer to queries like this:
query {
calc {
some: add(a: 1, b: 2)
some_other: add(a: 41, b: 1)
}
}
The expected answer is like this:
{
"data": {
"calc": {
"some": 3,
"some_other": 42
}
}
}
Now my problem is that I can’t figure out what to return in the resolver of the calc query. The first guess was to just return {:ok, %{some: 3, some_other: 42}}, but that doesn’t work. I tried a map with some and some_other key as strings. Also tried to return nested maps, and binary keys like "some:add" and "some: add". None of them worked. The only way Absinthe gives me a non-null response is to use the :add key in the return map, but that way I cannot distinguish between the two separate add calculations. (That means some and some_other collapses into the same value.)
What is the proper way to answer a query like this? What should I return from my resolver to get back two separate values for my tow aliases?
Trending in Questions
Other Trending Topics
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
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 1- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
benwilson512
Resolvers don’t care about field aliases (your “some” or “some_other”). Just return a value consistent with your resolver type eg {:ok, 42}.