0

Q: I would like to get to know the fields a user is selecting in a GraphQL query within the Absinthe graphql framework.

I have a hard time poking around in %Absinthe.Resolution{} as it is a vast blob of state, that goes with fragmented documentation over many files.

Given the following example. A user queries a post, that can return a union-type. The user is selecting id, role, parentId and slug on every Post-type encountered in the response.

fragment Component on Component {
  id
  role
  parentId
}

{
  post(slug: "super-paloma-sunglasses") {
    ... on Post {
      ...Component
      slug
    }
  }
}

Now I have a resolver:

def post(_root, %{slug: slug}, info) do
  # fields_by_type = queried_fields(info)
  result = App.Repo.execute(:document_by_slug, [slug])
  {:ok, result}
end

Now my problem is, that I am unable to gather the necessary information from info without completely understanding all the implementation details of Absinte.Resolution.

P.s. Being new to the Elixir Graphql implementation "Absinthe". I will obviously continue to work on a solution, and if I find one post it here, but maybe somebody else encountered something similar and has a solution already.

P.p.s.: I should not be that difficult, as this must be a quite common use case, as GraphQL empowers the server to be careful about the data he is fetching from a database for example.

Overbryd
  • 4,612
  • 2
  • 33
  • 33
  • `s/that goes with fragmented documentation over many files/I do not know how to get to the documentation/` https://hexdocs.pm/absinthe/overview.html – Aleksei Matiushkin Dec 01 '17 at 06:45
  • Please read carefully, and have a pinch of understanding of the subject matter, before you comment. There is nothing your comment helps me in. I quote from the documentation of ‘Absinthe.Resolution’: “...Please see the code itself for more information on individual blueprint sub modules.” So what exactly did you try to sell me here?! – Overbryd Dec 02 '17 at 10:59
  • I believe that you want to look into `info.definition.selections`. This will give you the selected fields. Then you can look for those field's definitions under `schema_node`. – Asker Jan 18 '18 at 19:38

0 Answers0