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
[MUSIC] 0:00 You've learned how to get data you want from a GraphQL backend, but 0:04 what about when you want to make changes? 0:08 That's where mutations come in. 0:11 In this stage, you'll be learning how to write mutations that will modify our data. 0:14 We'll start by going over the components that make up a mutation. 0:19 Just like a query, mutations are composed of three parts, the declaration, 0:23 the endpoint and the response fields. 0:28 The only component that really differs here is the declaration. 0:31 With a mutation, we use the mutation keyword instead of query. 0:34 This tells graph QL that we're gonna be changing something instead of just 0:39 retrieving something. 0:43 The format will use for calling the endpoint and 0:45 specifying the response fields remains the same. 0:48 Just like in a query, we specify which endpoint we'd like to call 0:51 in the curly braces following the mutation declaration. 0:56 In this case, we're calling the createMovie endpoint, 1:00 which will create a new movie with the fields we enter. 1:04 Even though we're sending data, 1:07 we're still interested in shaping our response to the format that we need. 1:09 With a query, we specify the fields we want returned 1:14 in the curly braces following the endpoint name. 1:17 So that's the basic anatomy of a mutation. 1:21 As you can see, mutations bear a lot in common with queries, the only significant 1:24 difference being that mutations always change some piece of data. 1:29 In the next video, you'll get to write your first mutation using scalar types. 1:33
You need to sign up for Treehouse in order to download course files.Sign up