What is GraphQL?
GraphQL is a query language and runtime for APIs that exposes a single endpoint where clients specify exactly which fields they want. Instead of many fixed endpoints, the client sends a query describing the shape of the response it needs.
This eliminates over- and under-fetching and is backed by a strongly-typed schema, at the cost of more setup and harder HTTP caching than REST.
Key points
- One endpoint; clients request exactly the fields they need.
- A strongly-typed schema describes all available data.
- Avoids over-fetching and under-fetching by design.
- Caching is harder than REST and needs dedicated tooling.
Example
query {
user(id: 1) { name email }
}Common uses
- APIs with many clients that need different data shapes
- Aggregating multiple data sources behind one endpoint
- Mobile apps minimizing payload size
- Rapidly evolving frontends