Gulliver

Gulliver

How to use nested arguments in Absinthe

Good morning ladies and gents,

I’d have a quick question regarding the Absinthe queries.

Is this following query possible at all:

{
  users(order: DESC) {
    id
    email
    clients(order: ASC) {
      id
      email
    }
  }
}

I couldn’t find any examples describing how to implement these nested queries. So far I’ve only managed to use arguments on the root level, like order: DESC, client_order: ASC, but that doesn’t look very clean.

I did this with my schema:

query do
    field :users, list_of(:user) do
      arg :order, :sorting
      resolve &Resolvers.users/3
    end
end

object :user do
    field :id, :id
    field :email, :string
    field :clients, list_of(:user)
end

I then tried to create a query for “clients” like this:

query do
    field :clients, list_of(:user) do
      arg :order, :sorting
      resolve &Resolvers.users/3
    end
end

but that doesn’t seem to do anything at all.

The error message I get when trying to add the arguments in the query is "message": "Unknown argument "order" on field "clients" of type "User".

First Post!

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Hey! Our guides need to go into this more, cause this comes up a fair bit.

You should check out How to write subqueries in absinthe? - #3 by astery which is basically the same question, and if you’ve for further questions afterward feel free to ping me!

Where Next?

Popular in Questions Top

chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 127536 1222
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement