Skip to main content

GraphQL

Pronunciation
GRAF-kyoo-EL
Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/graphql

In short

GraphQL is a query language and runtime for APIs that lets clients request exactly the data they need, often from a single endpoint in a single request.

What is GraphQL?

GraphQL is a way to build and use APIs in which the client writes a query describing the exact shape of the data it wants, and the server returns JSON in that same shape. It was created at Facebook in 2012, released as open source in 2015, and is now maintained by the GraphQL Foundation.

Every GraphQL API is built around a schema, a typed description of all the data and operations it offers. Clients send queries to read data, mutations to change it, and subscriptions to receive real-time updates. On the server, small functions called resolvers fetch the value for each field from a database, another API, or any other source.

A helpful analogy is a buffet versus a set menu. A REST endpoint is like a set menu that always serves the same plate, while GraphQL lets you choose exactly which dishes go on your plate. This is especially useful for mobile apps and complex user interfaces that need data from many related objects at once.

GraphQL is not a database and does not replace SQL; it sits in front of your data sources as an API layer. Compared with REST, it avoids over-fetching (receiving fields you don't need) and under-fetching (needing several requests to get everything), but it makes HTTP caching and rate limiting harder because most requests go to one endpoint.

At a glance

A client sends one GraphQL query to the single /graphql endpoint asking for a user's name and the titles of their posts, and the server answers with JSON in exactly that shape; with REST the same data would take two requests that return every field.query: the fields you want{ user(id: 42) { name posts { title } }}ServerPOST /graphqlone endpointresponse: the same shape{ "data": { "user": { "name": "Ada", "posts": [{ "title": "Hi" }] }} }REST: GET /users/42 + GET /users/42/posts = 2 requests, every field
The response mirrors the query line by line: the client gets the fields it named and nothing else, in one request.

Key takeaways

  • Clients specify exactly which fields they want in the response.
  • A typed schema describes all available data and operations.
  • Queries read data, mutations change it, and subscriptions stream updates.
  • Most GraphQL APIs expose a single endpoint, often /graphql.
  • GraphQL is an API layer, not a database.

Example

A GraphQL query for nested datagraphql
# Ask for a user's name and the titles of their 3 latest posts
query {
  user(id: "42") {
    name
    posts(last: 3) {
      title
    }
  }
}

# The response is JSON with exactly the same shape:
# { "data": { "user": { "name": "Ada", "posts": [{ "title": "..." }] } } }

Readers ask

Is GraphQL better than REST?

Neither is better in every case. GraphQL shines when clients need flexible, nested data from many sources, while REST is simpler to build, cache, and monitor for straightforward resources.

Is GraphQL a database?

No. GraphQL is a query language for APIs; the server's resolvers fetch the actual data from databases, other services, or files behind the scenes.

Does GraphQL use HTTP?

Usually, yes. Most GraphQL APIs receive queries as HTTP POST requests to a single endpoint, although the specification itself does not require a particular transport.

Often compared

See also

Sources

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings