Exercise: Implement a Mutation
Practice implementing a mutation for a GraphQL API.
Exercise source code
To get the source code for this exercise, run the following command in the project’s repository:
git checkout categories-mutation-exercise
How to start the project
To start the project, follow the same steps from the previous lesson.
Add a new mutation definition
First, we need to add a definition to a new mutation that will allow the creation of a new category. To create a category, our new mutation needs the slug
and name
parameters, both of type String!
.
We add the definition in the server/src/schema.graphql
file. We can either pass both parameters separately or combine them in an input type.
Here’s one version of a mutation schema definition:
Get hands-on with 1200+ tech skills courses.