Skip to content
Getting Digital

GraphQL

Also: GraphQL API, GraphQL schema, GraphQL query, GraphQL resolver

GraphQL is a query language for APIs and a server-side runtime for answering those queries: a client asks for precisely the fields it needs from a typed schema, in one request, instead of calling several fixed endpoints and discarding most of what comes back.

Assessment. GraphQL is appropriate for teams with many clients and many screens, where the shape of the data a front end needs changes faster than the back end can add endpoints. For a single product with one consumer, a well-designed REST interface is usually the simpler choice, because caching, rate limiting and authorisation are easier to manage per URL than per query.

GraphQL was created at Facebook in 2012 for its mobile applications, published as an open specification in 2015 and is maintained by the GraphQL Foundation; the current specification edition is dated October 2021. The server publishes a schema: types with named fields, each field with its own type, and three kinds of operation a client may send. A query reads, a mutation writes and then reads, and a subscription keeps a connection open so that the server can push data when an event happens. Because the schema is itself queryable, a client can ask the server what it offers, which is how editors autocomplete queries and how documentation stays in step with the code.

The practical difference from a REST API is who decides the shape of the response. REST fixes it per endpoint: a request for user 42 returns the user as the server designed it, and a screen that needs the user plus the last five orders makes two calls or asks for a bespoke endpoint. In GraphQL the client writes the shape, user 42 with the name and the totals of the last five orders, and the server assembles it by running a resolver function for each requested field. One request, no over-fetching, no under-fetching, and no new endpoint when a screen changes.

ConcernRESTGraphQL
Response shapeFixed by the server per endpointChosen by the client per query
Round trips for a composite screenSeveral, or a custom endpointOne
HTTP cachingWorks by URL out of the boxMostly POST to one URL; caching moves into the client or a gateway
Cost controlPer endpoint, easy to reason aboutPer query; needs depth and complexity limits
ToolingAny HTTP clientSchema-aware clients, introspection, code generation

The costs follow from the same design. Resolvers that fetch one row at a time turn a routine query for a hundred users and their orders into a hundred and one database calls, the N+1 problem, which batching libraries exist to solve. Every request is a POST to one URL, so the HTTP cache that a REST interface gets for free has to be rebuilt in the client or at a gateway, and caching strategy becomes a design task. Authorisation applies per field rather than per route. None of this is a reason to avoid GraphQL; it is the engineering a team takes on in exchange for client-driven queries, and it is why the style pays off in back-end and API work that serves many clients and rarely in a single-page site with one consumer.

In practice

A product page on a shop app needs the product, its three best reviews, the reviewer names and the current stock in the customer's region. Against a REST interface that is four requests on a mobile connection, or a product-page endpoint built for this one screen and kept forever. Against a GraphQL schema the app sends one query naming those fields; when the design adds the seller's rating next quarter, the query gains one line and the server changes nothing.

Often confused with

REST API
REST is an architectural style with resources at URLs and the server deciding each response; GraphQL is a query language with one endpoint and the client deciding each response. Both usually run over HTTP and answer in JSON.
SQL
SQL queries a relational database directly; GraphQL queries an API, and a resolver behind it may call SQL, another API or a cache. The term query is the only element they share.
JSON
JSON is the format a GraphQL server answers in; GraphQL is the language the client asks in. A GraphQL query is not JSON, although the variables sent with it are.

Key takeaways

  • →The client writes the shape of the response; the server resolves it field by field. That is the central idea and the source of every trade-off.
  • →HTTP caching and cost control do not come for free as they do with REST; plan the gateway, batching and query limits before launch.
  • →Choose it for many clients and fast-changing screens, not as a default replacement for a tidy REST interface.

Related concepts

  • RelatedREST API

    The two API styles solve the same problem with opposite decisions about who shapes the response.

  • Learn firstHTTP

    A GraphQL request is usually one POST over HTTP; the transport comes first.

Where this concept sits in the field

FAQ

Is GraphQL a database?
No. It is a layer in front of whatever stores the data. Each field in the schema has a resolver, a function that may read a database, call another service or return a computed value. The database can be relational, a document store or three different systems behind one schema.
Does GraphQL replace REST?
It replaces it where client-driven queries matter and coexists with it everywhere else. Many companies run a GraphQL gateway for their apps in front of REST services that other teams still call directly.
Which exams or courses cover it?
Vendor exams treat it lightly; AWS AppSync appears in the Developer Associate scope as a managed GraphQL service. The practical learning is a schema, a resolver and a client in one of the usual stacks, which the back-end courses teach after REST.

Sources

The primary text this definition rests on. Read it before relying on this one.

Last reviewed 3 October 2026 · Getting Digital