liveBook · Manning

GraphQL mutation

As explained in Quarkus in Action

A GraphQL mutation is a GraphQL operation that can add or modify data and may return data with the update.

A GraphQL mutation is an operation for changing existing data or adding new data. Like an SQL UPDATE or INSERT, or a REST PUT or POST, it accepts parameters and can return data with the update. section 4.4

Mutations differ from read-only queries in several practical ways:

  • Declare the operation with the mutation keyword. section 4.5.2
  • Pass input arguments, such as a CarInput object containing the fields needed to create a car. section 4.5.2
  • Select fields from the returned object; complex return types require an explicit field selection. section 4.5.2
  • Return the stored object, including generated values such as an ID, when those fields are selected. section 4.5.2

Registering a car

A register mutation adds a Peugeot 406 to a fleet and requests the returned license plate, model, manufacturer, and ID. The response echoes those values and includes the generated ID 3. Running the cars query afterward verifies that the database contains the new car. section 4.5.2

Figure 4.3 GraphiQL is an HTML and JavaScript-based UI for manually executing GraphQL operations.
figure

Use GraphiQL to enter, autocomplete, execute, and review GraphQL mutations through a browser-based interface. section 4.5.2

How Quarkus in Action covers it

How deep it goes
Defines operation semantics and demonstrates input, field selection, response echoing, and database verification without covering advanced GraphQL features.
Examples
Demonstrates a register mutation that creates a fleet car, echoes selected fields, and verifies persistence with a cars query.
What it assumes
Assumes familiarity with GraphQL fields and queries while introducing mutation syntax, input objects, and complex-result selection.
What you can do after
Apply it via GraphiQL by supplying mutation arguments, selecting response fields, executing the operation, and checking the resulting data.
How it connects
Relates mutations to GraphQL queries, SQL INSERT and UPDATE, REST POST and PUT, GraphiQL, and input object types.

Also explained in

Compare how 2 books explain GraphQL mutation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quarkus in Action. The section links point to the parts of the book it draws on.