One Endpoint, Many Shapes
GraphQL is a query language for APIs. Instead of many fixed endpoints, the client sends a query to a single endpoint and asks for exactly the fields it wants.
How It Works
The server publishes a typed schema, and clients query against it.
- A schema defines types and the fields each type exposes.
- A query asks for a specific tree of fields.
- The server returns JSON shaped exactly like the query.
- A mutation is the same idea for writes.
Strengths And Pitfalls
The shape it wants approach solves real problems.
- Clients avoid over fetching unneeded fields.
- Clients avoid under fetching that forces extra round trips.
- A single request can gather data from many sources.
The risks are on the server. A deeply nested query can be expensive, so servers add depth and cost limits. The classic backend trap is the N plus one problem, where one field triggers many database calls, usually solved with batching loaders. GraphQL trades a simple endpoint for a powerful but heavier query engine.
Key idea
GraphQL lets clients query a single typed endpoint for exactly the fields they need, ending over and under fetching, but shifts cost to the server which must guard against expensive nested queries and N plus one fetches.