Absinthe Nested Query

How can I achieve this format using GraphQL Absinthe in the server side? Please help. The property of user depends on the result of property id of property query with only user id as argument in the user query.

{
 property(id: 1) {
  id
  name
  user(id: 2) {
   id
   email
  }
 }
}

Nevermind. Solved it.

  object :property do
    field :id, :integer
    field :users, list_of(:user)

    field :user, :user do
      arg(:email, :string)

      resolve(fn property, %{email: email}, _ ->
        result =
          property
          |> Ecto.assoc(:users)
          |> where([u], u.email == ^email)
          |> Repo.one()

        {:ok, result}
      end)
    end
  end
3 Likes