GraphQL
Mutations
Write data and return the result.
By EZ4Code Team
mutationwrite
Code
mutation CreateBook($input: CreateBookInput!) {
createBook(input: $input) {
id
title
author {
name
}
}
}
mutation UpdateBook($id: ID!, $title: String) {
updateBook(id: $id, title: $title) {
id
title
}
}Explanation
Mutations perform side effects such as creating or updating records and then return a selection set of the resulting data. The spec executes multiple top-level mutations sequentially, in order, whereas query fields execute in parallel. Returning the changed object lets the client update its cache without an extra fetch.