liveBook · Manning

GraphQL

As explained in Grokking Software Architecture

GraphQL is an API query language and execution system that lets clients request structured data through a typed schema.

GraphQL is a query language and execution system for APIs. Clients request specific fields through a typed schema, rather than receiving every field an endpoint might return. section 6.4.2

Think of it as a personal shopper: ask for the chip’s name and the soda’s price, and get both in one response. This can reduce over-fetching and network round trips, which helps clients on unreliable or slow connections. section 6.4.2 section 6.4.3

The flexibility comes with tradeoffs:

  • Servers are more complex to implement, and caching is harder because requests can differ. section 6.4.2
  • GraphQL requests commonly use HTTP POST, even for reads. Queries do not change data; mutations do. A retried payment mutation could charge twice unless the request includes an idempotency key. 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 two different product fields and the matching response. section 6.4.2

Choose between GraphQL and REST by asking what the clients need and what tradeoffs the system can accept. GraphQL can combine targeted data in one call; REST offers predictable endpoints and standard HTTP caching. section 6.4 section 6.4.3

How Grokking Software Architecture covers it

How deep it goes
Explains targeted queries, round trips, tradeoffs, and mutation retry safety, but not server implementation.
Examples
Shows a shopper requesting a chip’s name and soda’s price, plus a warehouse scanner retrieving product, stock, and location data.
What you can do after
Evaluate GraphQL against REST by weighing round trips, client flexibility, caching, implementation complexity, and retry safety.
How it connects
Connects GraphQL with REST, HTTP POST, idempotency, and API contracts.

Also explained in

Compare how 8 books explain GraphQL →

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.