You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can see that a mutation can contain multiple fields, just like a query. There's one important distinction between queries, and mutations, other than the name:
194
-
195
-
**While query fields are executed in parallel, mutation fields run in series, one after the other.**
196
-
197
-
This means that even though we sent `createCharacter` and `addCharacterToEpisode` in one request, the first is guaranteed to finish before the second begins, ensuring that we create the character before trying to add it an episode.
198
-
199
192
#### Returning data from mutations
200
193
201
-
Just like in queries, you can ask for nested fields in the mutation result. This can be useful for fetching the new state of an object after an update:
194
+
Just like in queries, if the mutation field returns an object type, you can ask for nested fields. This can be useful for fetching the new state of an object after an update:
202
195
203
196
```graphql
204
-
mutationIncrementCredits($characterId: ID!) {
205
-
incrementCredits(characterId: $characterId) {
197
+
mutationIncrementCredits($humanId: ID!) {
198
+
incrementCredits(humanId: $humanId) {
206
199
totalCredits
207
200
}
208
201
}
209
202
```
210
203
211
-
In this case, the `incrementCredits` mutation field returns a `Character` object, so we can query the new value of `totalCredits` after giving that character some more credits. Otherwise, we would have needed to send two requests - one to update the credits, and another to get the new value - or guess at the new amount based on outdated data.
204
+
In this case, the `incrementCredits` mutation field returns a `Human` object, so we can query the new value of `totalCredits` after giving that character some more credits. Otherwise, we would have needed to send two requests - one to update the credits, and another to get the new value - or guess at the new amount based on outdated data.
205
+
206
+
#### Multiple fields in mutations
207
+
208
+
A mutation can contain multiple fields, just like a query. There's one important distinction between queries and mutations, other than the name:
209
+
210
+
**While query fields are executed in parallel, mutation fields run in series, one after the other.**
212
211
213
-
That's all! Now you know everything you need to know about GraphQL queries and mutations to build a pretty good application. For more advanced features and tips, check out the advanced section.
212
+
This means that if we send two `incrementCredits` mutations in one request, the first is guaranteed to finish before the second begins, ensuring that we don't end up with a race condition with ourselves.
0 commit comments