Implementing Mutations
Learn about mutations that allow changes to server-side data using GraphQL API.
So far, we’ve only worked with static data in a database that never changes. While that is fine for learning the basics of GraphQL, we really need to be able to create new records, as well as update and delete existing ones.
In this lesson, we’ll learn how to implement operations called mutations that change server-side data. First, let’s go back to the GitHub GraphQL Explorer to see how we can use existing mutations, and then we’ll implement a mutation in our application to create a new product posting.
Mutations in GraphQL
Before implementing our first mutation, let’s try to use an existing mutation provided by the GitHub API. In one of our first lessons, we used a query to fetch the user’s current status from GitHub, and now, we’ll try to update that status using a GraphQL mutation programmatically.
First, let’s look at how a GraphQL mutation is defined. To change the user’s status, we’ll use the changeUserStatus
mutation. Here’s how it’s defined in the GraphQL schema:
Get hands-on with 1200+ tech skills courses.