Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Anatomy of a Mutation1:38 with Isaac Lee Morris
In this video, we will go over the different parts that make up a GraphQL mutation, before diving into each one in more detail in the videos that follow.
- Mutation - A special kind of GraphQL query that causes changes to the data available on the backend
You might be wondering why we need a different declaration keyword for mutations; this basically allows us to optionally optimize our backend, since we know that unlike mutations, queries only retrieve information, and won’t cause any side effects.
Tutorial: Getting started with GraphQL queries and mutations, by Tim Lucas
You've learned how to get data you want from a GraphQL backend, but
what about when you want to make changes?
That's where mutations come in.
In this stage, you'll be learning how to write mutations that will modify our data.
We'll start by going over the components that make up a mutation.
Just like a query, mutations are composed of three parts, the declaration,
the endpoint and the response fields.
The only component that really differs here is the declaration.
With a mutation, we use the mutation keyword instead of query.
This tells graph QL that we're gonna be changing something instead of just
The format will use for calling the endpoint and
specifying the response fields remains the same.
Just like in a query, we specify which endpoint we'd like to call
in the curly braces following the mutation declaration.
In this case, we're calling the createMovie endpoint,
which will create a new movie with the fields we enter.
Even though we're sending data,
we're still interested in shaping our response to the format that we need.
With a query, we specify the fields we want returned
in the curly braces following the endpoint name.
So that's the basic anatomy of a mutation.
As you can see, mutations bear a lot in common with queries, the only significant
difference being that mutations always change some piece of data.
In the next video, you'll get to write your first mutation using scalar types.
You need to sign up for Treehouse in order to download course files.Sign up