Absinthe
Absinthe is the GraphQL toolkit for Elixir, an implementation of the GraphQL specification built to suit the language’s capabilities and idiomatic style.
The GraphQL query
First, define a GraphQL schema, so we know what we can query
Then, we can make the query
- I was confused about
&Resolvers.Content.list_posts/3
syntax - You can think of this as just passing the function pointer. it gives Absinthe a reference to the function, which it will later call when the client actually makes a graphQL query
Why is the query called a schema?
Cuz from a database background,
schema
is not really associated with queries.In GraphQL, the schema is a core concept that defines the shape of the data and possible operations that clients can perform via queries or mutation
- Revisit graphql schema
This lists posts is essentially the implementation that actually makes the SQL query!! under the hood, it’s this
This is very basic. We want to query for a specific id
Absinthe types
Instead of this
Do this
Interfaces
https://hexdocs.pm/absinthe/Absinthe.Type.Interface.html
Because sometimes it’s for the interface to determine the implementing type of a resolved object, you must either:
- Provide a :resolve_type function on the interface
- Provide a :is_type_of function on each implementing type