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".

1 Like

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? which is basically the same question, and if you’ve for further questions afterward feel free to ping me!