Making a Query

A GraphQL query is the way that API users can ask for specific pieces of information. We’ve defined the shape of our GraphQL MenuItem type, but to support users getting menu items, we need to provide two things:

  • A way for users to request objects of the type
  • A way for the system to retrieve (or resolve) the associated data

The key to the first objective is defining a special object type to serve as the entry point for queries on a GraphQL schema. We already defined it when we used the query macro earlier.

The query macro is just like object, but it handles some extra defaults for us that Absinthe expects. Since we’ve already defined a blank query object, let’s take a look at what it looks like in IEx, too:

​ ​iex(1)> ...

Get Craft GraphQL APIs in Elixir with Absinthe now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.