Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

GraphQL · Const

Mutation

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.

How it works

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.

Syntax

mutation OperationName($variable: Type!) { field(argument: $variable) { selectedField } }

Returns

The selected fields of the mutation field's result.

Key points

  • Mutations let clients request changes to data through a GraphQL server.
  • A schema declares mutation actions as fields on a root operation type.
  • The conventional root type for these write fields is named Mutation.
  • A mutation field can receive arguments, including structured input values.
  • Input object types are suitable for bundling related mutation arguments.
  • Multiple requested mutation fields run one after another rather than in parallel.

Common mistakes

  • A mutation must use the mutation operation type; unlike the shorthand form available for queries, mutations cannot omit that keyword.
  • Side effects belong at the mutation operation's top level; other field resolvers should remain side-effect-free and idempotent.
  • Do not assume mutation fields run concurrently: top-level mutation fields execute sequentially.

Example: Creating a review

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.

When to use it

Creating data

Create a record such as a review, user, or order and request its resulting fields.

Updating data

Change existing records through a schema-defined update action.

Deleting data

Remove records when the schema exposes a delete mutation.

Domain actions

Perform a domain-specific write action represented by a dedicated mutation field.

Interview questions

QWhat is a GraphQL mutation?

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.

QHow does a schema expose a mutation?

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.

QHow is a mutation written and executed?

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.

  • Query
  • Subscription
  • Mutation type
  • mutation operation
  • input object types
  • selection set

Source: Remove existing data. Checked 2026-10-15.