Creating data
Create a record such as a review, user, or order and request its resulting fields.
GraphQL · Const
A GraphQL mutation is an operation for changing server-side data and selecting the resulting data. Mutation fields are exposed on the schema’s Mutation root and execute serially at the top level.
A mutation is a GraphQL operation for changing server-side data and then selecting the resulting data. The schema exposes write actions as fields on its Mutation root; those fields may take arguments, and top-level mutation fields execute serially so side effects occur in order.
mutation OperationName($variable: Type!) { field(argument: $variable) { selectedField } }The selected fields of the mutation field's result.
Mutation.mutation CreateReview($episode: Episode!, $review: ReviewInput!) {
createReview(episode: $episode, review: $review) {
stars
commentary
}
}This operation sends variables to a mutation field and requests the fields the server should return from the created review.
Create a record such as a review, user, or order and request its resulting fields.
Change existing records through a schema-defined update action.
Remove records when the schema exposes a delete mutation.
Perform a domain-specific write action represented by a dedicated mutation field.
A mutation is the write-oriented GraphQL operation. It invokes fields exposed by the schema's Mutation root, and the client selects the response fields it wants returned.
Follow-up: Why are mutation fields serialized? Because writes can have side effects, serial execution preserves the requested order and helps avoid races between those effects.
Mutation fields are defined on the Mutation object type, just as query fields are defined on the Query root. They can accept arguments, including input object arguments, and return an object whose fields the client can select.
Follow-up: How would you model a complex write? Use an input object argument to group the write inputs, then return a payload or result object with fields useful to the client.
The client sends an operation beginning with mutation, optionally names it, supplies variables or arguments, and includes a selection set for the returned data. The server executes the top-level mutation fields in series.
Follow-up: Can a mutation contain several top-level fields? Yes; they are executed serially in the order requested, so their ordering matters when they produce related side effects.
QuerySubscriptionMutation typemutation operationinput object typesselection set