What is GraphQL?

In short
GraphQL is a query language for APIs and a runtime that runs those queries against your data. A client asks for exactly the fields it needs, and the server returns just those fields in a predictable shape. It is built on a strongly typed schema, which describes what data is available.
How it works
A GraphQL API exposes one endpoint. Instead of many URLs, each returning a fixed set of data, the server publishes a schema. The schema describes the types of data available and the fields on each type. A client reads that description and writes a query that names the fields it wants.
The server then fills in only those fields. If you ask for a user's name and email, you get a name and an email, nothing more. The response has the same nested shape as the query, so the client can often use it directly.
The official documentation describes this as a strong type system. Every field has a declared type, and the server checks each query against the schema before it runs. A typo or a wrong type is reported as an error without touching your data.
Core building blocks
GraphQL work is split into three kinds of operation:
- Queries read data.
- Mutations change data, such as creating, updating or deleting records.
- Subscriptions push updates to a client when something changes.
The schema is written in a small language called the schema definition language. It declares object types, scalar types such as String or Int, enums, lists and input types. Each field can be marked as nullable or non-null, which tells clients whether a value may be missing.
Behind each field sits a resolver. A resolver is a function on the server that knows how to fetch the value for that field, for example from a database or another service. GraphQL calls the resolvers needed for a query and assembles the answer.
A simple example
Suppose the schema has a User type with id, name and email fields. A client sends this query:
{ user(id: "42") { name email } }
The response contains a data object with a user that has only name and email. If the client later needs the id as well, it adds one line to the query. The server does not need a new endpoint for that change.
Responses are organized into data, errors and extensions. The data part holds the results. The errors part lists problems, and it can appear alongside partial data. Extensions carry extra metadata that a server chooses to include.
Why teams choose it
The main benefit is that clients control the shape of the data. A mobile app can ask for a small payload, while a web dashboard asks for more. Both use the same API. This often reduces the number of round trips needed to build a screen, since one query can fetch related objects together.
GraphQL also supports introspection. A client can ask the server to describe its own schema, which lets tools provide autocomplete and documentation. Many developer tools rely on this feature.
The approach also encourages a versionless style. Instead of publishing v2 and v3 of an API, teams add new fields and mark old ones as deprecated. Clients that do not use the old fields are not affected.
Common mistakes
Beginners often assume GraphQL replaces every other technology. It does not remove the need for a database or for authorization. Those rules still live on the server, in the resolvers or in the layer around them.
Another common issue is the N+1 problem. If a list of items each triggers a separate database call inside a resolver, the server makes many small requests. Batching and caching strategies help solve this, and the best practices guides cover them.
Finally, clients can request deeply nested data. Without limits on query depth or cost, a single request can be expensive. Servers usually add these limits on purpose.
Alternatives
REST is still a strong choice for simple resources with stable shapes, and it benefits from standard HTTP caching. GraphQL fits better when many clients need different slices of the same data. Choose the tool that matches your data access pattern and your team's experience.
FAQ
Is GraphQL a replacement for REST?
Not always. GraphQL is a good fit when clients need different subsets of the same data. REST can still be simpler for basic resources and works well with standard HTTP caching.
Does GraphQL need a special database?
No. A GraphQL server can sit in front of any data source, such as a SQL database, a document store or another API. Resolvers decide how each field gets its value.
Do GraphQL APIs have versions?
The approach is designed to avoid numbered versions. Teams add new fields and mark old ones as deprecated, so existing clients keep working while they migrate.
Is GraphQL only for web apps?
No. Any client that can send an HTTP request can use GraphQL, including mobile apps, command-line tools and server-to-server services.
Sources
This page is based on the official documentation below. Read it for full detail.
GraphQL — official documentation ↗GraphQL in the news
Mock Service Worker 3.0 drops CommonJS-era builds, intercepts at the socket level and adds GraphQL subscriptions
Mock Service Worker has released version 3.0 as an ESM-only package, with a new Node.js interception layer that works at the TCP and TLS level and support for GraphQL subscriptions. Teams upgrading from v2 face breaking changes.
