liveBook · Manning

GraphQL mutation

As explained in Building Web APIs with ASP.NET Core

A GraphQL mutation is an operation that requests a state-changing action from a GraphQL server and can return selected resulting fields.

A GraphQL mutation requests a state-changing action from a server and selects the fields returned afterward. In the board-game API, it updates a game and returns its new name. section 10.2.4

Use a mutation through this practical sequence:

  • Authenticate first: obtain a JWT through SwaggerUI, then configure BananaCakePop with Bearer authorization. Protected mutation methods otherwise return 401 Unauthorized. section 10.2.4
  • Send a mutation containing the target entity's identifier and changed values, then select the response fields needed for confirmation. section 10.2.4
  • Run a separate query afterward to confirm that the change was saved in the database. section 10.5.2

Rename a board game

The following operation changes board game 1 and requests only the resulting name: mutation { updateBoardGame(model: { id: 1, name: "Die Macher (v2)" }) { name } }. A successful response returns "Die Macher (v2)". section 10.2.4

Figure 10.4 BananaCakePop Authorization settings
10-04

Use the authorization settings to select Bearer authentication and paste the JWT before executing a protected mutation. section 10.2.4

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Walks through token setup, mutation execution, and database verification, but does not detail server-side mutation implementation.
Examples
Demonstrates renaming Die Macher and assigning a revised name to Axis & Allies.
What it assumes
Assumes GraphQL query syntax, BananaCakePop, SwaggerUI login, and bearer-token retrieval.
What you can do after
Operate/configure BananaCakePop to authorize and execute a mutation, then verify the saved change with a query.
How it connects
Connects mutations with authorization, bearer tokens, JWTs, GraphQL queries, and database persistence.

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 Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.