GraphQL
In plain English
Plain definition
GraphQL is a query language and runtime for APIs that lets clients request precisely the fields they need from a single endpoint, reducing over-fetching but requiring careful schema, depth and cost governance to avoid abuse.
Technical Definition
GraphQL defines a strongly typed schema using the GraphQL Schema Definition Language (SDL), composed of types, fields, queries, mutations and optionally subscriptions. A GraphQL server exposes a single HTTP (or other transport) endpoint that receives a query document, validates it against the schema, resolves each field through resolver functions, and returns a JSON response whose shape mirrors the query. Unlike REST, where the server dictates response structure per endpoint, GraphQL puts response shaping in the client’s hands while the server retains full control over what operations, fields and depth are permitted.
Operational Relevance
In production systems, GraphQL is typically deployed as a gateway or service layer in front of one or more backend data sources (databases, microservices, third-party APIs). Operational concerns include query complexity and depth limiting, N+1 resolver call patterns, caching (which is harder than REST because responses are not URL-keyed), authentication and field-level authorisation, and observability of individual resolver latency rather than whole-endpoint latency. Because a single query can traverse many resolvers, a poorly bounded query can generate disproportionate backend load compared with an equivalent REST call.
Architecture Relationship
GraphQL sits at the API contract layer, commonly positioned as a Backend-for-Frontend (BFF) or federation layer that aggregates multiple internal services behind one schema. It is frequently combined with API gateways, schema federation tools, and persisted-query mechanisms to reduce arbitrary client-driven load. It does not replace the underlying data stores or service boundaries; it is a query and contract layer on top of them, and its correctness depends on resolvers enforcing the same authorisation and validation rules that would otherwise sit in REST controllers.
Example
A client requesting a user’s name and their five most recent orders in one round trip sends a single query document naming the user field, its name sub-field, and an orders connection with a limiting argument, for example:
query {
user(id: "123") {
name
orders(limit: 5) {
id
total
}
}
}
The server validates this against the schema, resolves user and then orders (potentially via separate backend calls), and returns a JSON object containing only the requested fields.
Common Misunderstanding
A frequent misunderstanding is that GraphQL is inherently faster or more secure than REST. It is neither by default. Flexibility in query shape means the server must explicitly enforce depth limits, complexity budgets and field-level authorisation; without those controls, GraphQL can expose more surface area for expensive or unauthorised queries than a fixed set of REST endpoints would. GraphQL also does not automatically solve caching or rate limiting; these require deliberate design.
Related Terms
- REST — an alternative API style using fixed, resource-oriented endpoints.
- Schema Definition Language (SDL) — the syntax used to declare GraphQL types and operations.
- Resolver — the server-side function that supplies data for a schema field.
- N+1 query problem — a common resolver performance issue in GraphQL backends.
Further Reading and Verification
Practitioners should consult the canonical GraphQL documentation for schema design, execution semantics and security guidance, and confirm any version- or tooling-specific behaviour (for example, specific server implementations’ depth-limiting features) against the current release notes for the server library in use before relying on it operationally.