APIs
GraphQL
⚠️

The GraphQL API is still work in progress and some features like filtering and sorting is currently not yet implemented! Changes to the API are expected to happen.

GraphQL API

Our GraphQL API provides a flexible and powerful way to interact with the Potter DB. This section will introduce you to the key aspects of our GraphQL API and how to leverage its capabilities.

GraphQL Endpoint

To make GraphQL queries and mutations, send POST requests to the GraphQL endpoint (/graphql) with your queries and variables in the request body. The API expects the request body to be in JSON format.

Querying Data

GraphQL allows you to request precisely the data you need. To construct a query, specify the fields you want to retrieve and their relationships. For example:

{
  books(first: 3) {
    totalCount
    pageInfo {
      hasNextPage
    }
    edges {
      node {
        title
        releaseDate
        chapters {
          edges {
            node {
              title
              slug
            }
          }
        }
      }
    }
  }
  character(slug: "harry-potter") {
    name
  }
}

In this query, we are requesting the title and releaseDate of the first three books, as well as the title and slug of all chapters of each book. Additionally, we are requesting the name of the character with the slug harry-potter.

Schema

To get an overview of the schema of the GraphQL API have a look at our GraphQL Schema (opens in a new tab).