GraphQL APIs
The BookNook home screen needs a member's name, their three current loans, and each loaned book's title and cover. With REST that is one call for the member, one for the loans, then one per book, and every response carries fields the screen never shows. GraphQL flips this: the client describes exactly the shape it wants, and gets that shape back in one round trip.
The rule
One endpoint, one typed schema; the client picks the fields.
A GraphQL API publishes a schema: the types it knows and the fields on each, all strongly typed.
type Book { id: ID! title: String! coverUrl: String }
type Loan { id: ID! due: String! book: Book! }
type Member { id: ID! name: String! loans(active: Boolean): [Loan!]! }
type Query { member(id: ID!): Member }The client sends a query that mirrors the shape it needs, usually as POST /graphql:
query HomeScreen {
member(id: 7) {
name
loans(active: true) { due book { title coverUrl } }
}
}The response has the same shape, and nothing more:
{ "data": { "member": { "name": "Asha",
"loans": [ { "due": "2026-10-09", "book": { "title": "The Hobbit", "coverUrl": "/c/42.jpg" } } ] } } }- Queries read data. Mutations change it, like
borrowBook(bookId: 42). Subscriptions push updates over a long-lived connection. - This fixes over-fetching (getting fields you do not need) and under-fetching (needing several calls to build one screen).
It has costs too:
- Caching is harder: everything is a
POSTto one URL, so ordinary HTTP caches cannot tell queries apart. - Errors look different: a response often comes back as
200 OKwith anerrorsarray besidedata, so clients must check the body, not just the status. - Expensive queries: a client can ask for deeply nested data in one request, so servers need limits on depth and cost.