GraphQL
GraphQL is an open-source API query language developed by Facebook that lets clients specify the exact shape and fields of the data they need, receiving precisely that structure in response; Clients send queries or mutations as structured strings to a single POST endpoint; GraphQL excels in product APIs where multiple clients (web, mobile, third-party) need different data shapes
GraphQL is an open-source API query language developed by Facebook that lets clients specify the exact shape and fields of the data they need, receiving precisely that structure in response. A single GraphQL endpoint replaces dozens of REST endpoints.
How it works
Clients send queries or mutations as structured strings to a single POST endpoint. The GraphQL server resolves each requested field via resolver functions, potentially fetching data from multiple sources, then returns a JSON response matching the query shape exactly.
Key facts
- Single endpoint: All operations go through one URL, with operation type determined by the query
- Strongly typed schema: The schema defines all types and relationships, enabling introspection and tooling
- N+1 problem: Naive resolver implementations can generate excessive database queries; DataLoader batching is a common fix
For builders
GraphQL excels in product APIs where multiple clients (web, mobile, third-party) need different data shapes. The schema-first approach also provides a living contract that improves collaboration between frontend and backend teams.
Sources
- IETF. RFC 9110: HTTP Semantics. datatracker.ietf.org
- IETF. RFC 9112: HTTP/1.1. datatracker.ietf.org
- Fielding, R. (2000). Architectural Styles and the Design of Network-based Software Architectures (REST). UC Irvine. ics.uci.edu
- OWASP. API Security Top 10 (2023). owasp.org
- MDN Web Docs. HTTP reference. developer.mozilla.org