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







