February 2020
Intermediate to advanced
404 pages
8h 42m
English
A REST API has methods such as GET, POST, PUT, and DELETE. The method itself describes the operation of the API call. Does GraphQL have something similar? Yes – mutations. A mutation is a GraphQL client query that updates the state of a resource on the server.
Let's look at an example of a counter API. A counter API allows clients to increment and return the counter value. In REST, this is a POST method call. In GraphQL, we have to define mutations in the client query to create-then-fetch results from the server.
Say the GraphQL schema looks like this:
type Query { counter: Count}type Count { id: Int value: Int}
The client query can fetch the count value for an id:
{ counter(id: "250") { value }}
This query fetches the ...
Read now
Unlock full access