Making a Query
Learn how to write queries for GraphQL.
We'll cover the following
Query creation
A GraphQL query is a way API users ask for specific pieces of information. We’ve defined the shape of our GraphQL MenuItem
type. However, to support users getting menu items, we need to provide two things:
-
A way for users to request the type’s objects.
-
A way for the system to retrieve the associated data.
The key to the first objective is to define 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 like an object, but it handles some extra defaults for us that Absinthe
expects. Since we’ve already defined a blank query object, let’s see what it looks like in IEx, too:
iex(1)> Absinthe.Schema.lookup_type(PlateSlateWeb.Schema, "RootQueryType")
The result looks something like this:
Get hands-on with 1400+ tech skills courses.