liveBook · Manning

GraphQL query

As explained in Grokking Software Architecture

A GraphQL query is an operation that requests data without changing it.

A GraphQL query requests data without changing it. You choose the fields you need, and one query can fetch selected details from multiple resources. Even when sent over HTTP POST, a query is a safe read: repeating it does not change the data. This differs from a mutation, which changes data. section 6.4.2

Listing 6.2 GraphQL Request/Response
# The Request (Your Shopping List)
query { 
  chipItem: product(id: "123") { 
    name # I only want the name for the chips 
  } 
  sodaItem: product(id: "456") { 
    price # I only want the price for the soda 
  } 
}
 
# The Response
{
  "data": {
    "chipItem": { "name": “Salt & Vinegar” },
    “sodaItem”: { “price”: 1.50 }
  }
}

See a request for the chip’s name and the soda’s price, and the response containing only those fields. section 6.4.2

How Grokking Software Architecture covers it

How deep it goes
Defines queries as naturally idempotent reads and illustrates field selection, without detailing server execution.
Examples
Shows one query requesting a chip’s name and a soda’s price, and repeated reads of a milk price.
What you can do after
Understand how to request selected data in one operation and why repeating a query does not change it.
How it connects
Connects GraphQL queries to REST GET semantics and distinguishes them from mutations.

Also explained in

Compare how 3 books explain GraphQL query →

Related concepts

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