Search⌘ K

Exercise: Add Categories to the API

Explore how to extend a GraphQL backend by adding a new Category type and a query to fetch products by category slug. This lesson guides you through updating the schema, creating resolvers, and testing your API to enhance product categorization.

Let’s put our newly acquired skills to use! In this exercise, we’ll practice adding a new type and a new query to our API. This lesson will outline what we want to add and will provide us with a link to the starter project. There will also be step-by-step instructions for how to implement the solution.

Exercise source code

To get the source code for this exercise run the following command in the project’s repository:

git checkout categories-exercise

Practice demo

Let’s practice what we’ve learned so far in the provided playground.

{
  "ext": "js,graphql",
  "delay": 2000
}
Empty demo

What we’re implementing

In this exercise, we’re going to add support for product categories to our API. Each product might belong to one of a few categories, such as Education or API.

Every instance of the Category type will have the following three types:

  • id: A
...