(This is Part 3 of a series: Part 1, Part 2, Part 4)

A GraphQL API is defined by a schema that describes everything that’s possible. And GraphQL clients can introspect that schema. In this 6-minute video, you’ll see how!

For example, the schema for a vacation destination GraphQL API might support a query for a specific place. And that query takes an ID as an argument and returns a Place object type:

type Query {
  place(id: ID!): Place
}

The Place object type might look something like this:

type Place {
  id: ID!
  name: String!
  description: String
  location: String!
  maxGuests: Int!
  perNight: Decimal!
  wifi: Boolean!
  bookings: [Booking]
  reviews: [Review]
}

It has several scalar fields, and also indicates a relationship between place, bookings, and reviews.

So when you send in a query for a place, you can ask for any of these fields, like so:

query {
  place(id: 3) {
    name
    location
    perNight
    bookings {
      startDate
      endDate
    }
    reviews {
      rating
      comment
    }
  }
}

How do GraphQL clients know what’s possible? Well, they can introspect the schema!

So, how do you go about implementing a GraphQL API in Elixir? Absinthe makes building a GraphQL API a breeze for Elixir developers. And that’s the topic we explore in the next video.

Unpack a Full-Stack GraphQL App Layer-By-Layer

Learn what it takes to put together a full-stack GraphQL app using Absinthe, Phoenix, and React in our Unpacked: Full-Stack GraphQL video course. No need to piece together solutions yourself. Use this application as a springboard for creating your own GraphQL apps!