A different shape of API
GraphQL exposes a single endpoint backed by a typed schema. Instead of many fixed responses, the client writes a query naming exactly the fields it wants, and the server returns just those, eliminating the over and under fetching common in REST.
Schema building blocks
- Types define objects with named, typed fields.
- Queries are the read entry points into the graph.
- Mutations are the write entry points.
- Resolvers are functions that fetch the value for each field.
Designing the graph well
- Model relationships as edges between types so a query can traverse from user to orders to items in one round trip.
- Mark fields non null only when truly guaranteed, since a null in a non null field fails the whole branch.
- Think in terms of the client's needs, not your database tables.
The strength is precision and a strongly typed contract. The cost is that arbitrary client queries can be expensive, which you control with depth and complexity limits.
Key idea
GraphQL exposes a typed graph where clients request exactly the fields they need, traded against query cost you must bound.