
A product screen rarely maps neatly onto one REST endpoint. A mobile profile page needs the user, their last five orders and the status of each shipment; with a classic REST API that is three or four requests, each returning more fields than the screen uses. Multiply that by every screen and every client, and the backend team ends up adding custom endpoints for each new view. GraphQL turns the question around: the client describes the shape of the data it needs, and the server returns exactly that shape in one response.
This article explains what GraphQL is, how a GraphQL server works, where it fits, where REST is still the better choice, and how it compares with the alternatives.
What is GraphQL?
GraphQL is an open-source query language for APIs and a server-side runtime that executes those queries against a type system you define for your data. It is not tied to a database, a storage engine or a programming language. A GraphQL server sits in front of whatever you already have, whether that is a SQL database, a document store, other microservices or a third-party API, and exposes it through one typed schema.
Facebook started building GraphQL in 2012, when it rebuilt its mobile apps natively and needed a more efficient way to load the News Feed over mobile networks. In July 2015 the company published a working draft of the specification together with GraphQL.js, a reference implementation in JavaScript, and opened both to the community.
Since then GraphQL has moved out of Facebook's hands. On 6 November 2018 the Linux Foundation announced the GraphQL Foundation, a neutral home for the specification, GraphQL.js and related tools. Implementations now exist for almost every server language, from Java and C# to Python, Go and Ruby.
How GraphQL works
The schema is the contract. A GraphQL API is described by a schema written in the Schema Definition Language (SDL). It lists every type, such as User, Order or Shipment, every field on those types and how they relate. Clients can only ask for what the schema declares, and the server validates every query against it before running anything.
Three kinds of operations. A query reads data, a mutation changes it, and a subscription keeps a connection open so the server can push updates when something changes, usually over WebSockets.
Resolvers fetch the data. Every field in the schema is backed by a resolver, a function that knows where its value comes from. A query for a user and their orders runs the user resolver, then the orders resolver for that user, and assembles the result into the nested shape the client asked for.
One endpoint, client-shaped responses. Most GraphQL APIs expose a single URL, typically /graphql, and accept queries over HTTP POST. The response mirrors the query: if the client asks for a user's name and the titles of their orders, that is all it receives, normally as JSON.
Introspection. A GraphQL server can describe its own schema. Tools such as GraphiQL use this to offer autocomplete and documentation in the browser, and code generators use it to produce typed client code, for example TypeScript types that match the API exactly.
Key features
- Exact data fetching: clients request only the fields they use, which removes over-fetching and the chains of requests that cause under-fetching.
- Strongly typed schema: the contract between front end and back end is explicit, validated and machine-readable.
- Single request for nested data: related objects come back in one round trip instead of several.
- Evolution without versions: new fields can be added freely, and old ones marked
@deprecatedinstead of shipping a/v2API. - Real-time subscriptions for live dashboards, chat and notifications.
- A broad tool ecosystem: GraphiQL for exploring APIs, DataLoader for batching, Apollo and Relay on the client, and server libraries for most languages.
Where GraphQL is used
- Products with several clients, where a web app, an iOS app and an Android app need different slices of the same data.
- Mobile apps on slow networks, where fewer and smaller responses make a visible difference.
- API gateways over microservices, where one schema stitches data from many services, often with a federation approach.
- Public developer APIs: GitHub offers a GraphQL API alongside its REST API, and Shopify exposes its Admin API through GraphQL.
- Front-end-heavy SaaS products whose screens change often and should not wait for a new endpoint each time.
When to choose GraphQL, and when not to
Choose GraphQL when:
- Several clients consume the same data in different shapes.
- Screens combine data from many related entities or several backend services.
- Front-end teams change views often and need to move without backend releases for every change.
- You want a typed, self-documenting contract between teams.
Look elsewhere when:
- The API is simple CRUD over a handful of resources. REST is easier to build, document and operate.
- HTTP caching at the CDN level is central to performance. REST GET requests cache naturally; GraphQL needs persisted queries or application-level caching to get close.
- You need high-throughput, service-to-service calls with strict contracts. gRPC is designed for that.
- The team has no experience securing GraphQL. Flexible queries mean a client can ask for very deep or expensive data, so depth and complexity limits, timeouts and authorisation per field are not optional.
The most common production problem is the N+1 query: a list of 50 orders triggers 50 separate database calls for their customers. Batching with DataLoader, or careful resolver design, solves it, but it has to be planned from the start.
GraphQL and its alternatives
| Approach | Contract | Strength | Best fit |
|---|---|---|---|
| GraphQL | Typed schema (SDL) | Client-shaped queries, one endpoint | Multi-client products, aggregating many sources |
| REST | Resources and HTTP verbs, often OpenAPI | Simple, cache-friendly, universal | Public APIs, CRUD services, CDN-heavy reads |
| gRPC | Protocol Buffers | Fast binary calls, streaming | Internal service-to-service traffic |
| tRPC | TypeScript types shared directly | Shared server and client types, no schema step | Full-stack TypeScript apps in one repository |
The usual question is "GraphQL or REST?", and the honest answer is that they solve different problems. REST models resources and lets HTTP do a lot of work for you; GraphQL models a graph of data and lets clients choose what to read from it. Many systems use both: REST, documented with Swagger, for public and simple endpoints, and GraphQL as the layer that powers rich client applications.
On the server side, GraphQL fits naturally into a Node.js backend, and NestJS has first-party GraphQL support with both schema-first and code-first approaches. For live updates, subscriptions compete with plain WebSocket libraries such as Socket.IO; a subscription is the better fit when updates follow the same types as the rest of the API.
How we use GraphQL at Internative
We use GraphQL to build flexible APIs that keep up with front ends whose needs keep changing. Its strong typing and introspection help us design API contracts that stay maintainable over time and give the developers on both sides of the API a better working experience.
If you are planning a product with several clients, or a front end that needs data from many services, our web application development team can help you decide whether GraphQL, REST or a mix of both fits your architecture.
Frequently asked questions
Is GraphQL better than REST?
Neither is better in general. GraphQL is stronger when many clients need different shapes of related data and when front ends change often. REST is simpler, caches better at the HTTP level and is the more familiar choice for public and CRUD-style APIs. Many teams run both.
Is GraphQL a database?
No. GraphQL is a query language and runtime for APIs. It does not store data; resolvers fetch data from databases, other services or external APIs. The "QL" invites the comparison with SQL, but GraphQL sits in the API layer, not in the database.
Is GraphQL just JSON?
No. Queries are written in GraphQL's own syntax, not in JSON. Responses are usually serialised as JSON, which is why the two are often confused, but the specification does not require a particular response format.
Is GraphQL faster than REST?
Not automatically. GraphQL can reduce the number of requests and the size of responses, which helps on mobile networks. A poorly designed GraphQL server can also be slower than REST, for example because of N+1 database queries or missing caching. Performance depends on resolver design, batching and caching, not on the protocol.
What is GraphQL used for?
GraphQL is used to build APIs for web and mobile apps that need flexible access to related data, to put one schema in front of several microservices, and to offer public developer APIs where consumers choose the data they need.
Keep reading
The articles that follow this one.



