What is GraphQL? GraphQL vs. REST Explained

Home Glossary What is GraphQL? GraphQL vs. REST Explained

GraphQL is a query language and runtime for APIs. Instead of calling several fixed endpoints, the client sends one query to a single endpoint and describes exactly which data it wants, including related data, and gets exactly that back. GraphQL was developed at Facebook in 2012, open-sourced in 2015, and is now maintained by the GraphQL Foundation. GitHub and Shopify are well-known platforms with a GraphQL API.

How does GraphQL work?

  • Schema: the server defines a strongly typed schema of all available types, fields and relations, which doubles as documentation.
  • Queries: the client asks for specific fields, for example a customer with only their name and their last five orders, in one request.
  • Mutations: operations that create, change or delete data.
  • Subscriptions: real-time updates pushed to the client, usually over a WebSocket.
  • Resolvers: server-side functions that fetch the data for each field, from a database, another API or a microservice.

GraphQL vs. REST

With REST, the server decides what each endpoint returns. That often means over-fetching (receiving more data than you need) or under-fetching (needing several requests to collect everything). GraphQL solves both: one request, exactly the right fields. That is especially useful for apps and front-ends with many different screens, and for APIs used by many different clients.

REST remains simpler for straightforward APIs, works naturally with HTTP caching, and is familiar to every developer. GraphQL makes caching, rate limiting and performance harder: a single complex query can put a heavy load on the server, and naive resolvers cause the "N+1 problem" of many small database queries. Production GraphQL APIs therefore need query depth and complexity limits, batching (for example with DataLoader) and good monitoring.

When is GraphQL a good choice?

GraphQL fits when several clients (web, mobile, partners) need different views of the same data, when the data model has many relations, or when you combine several back-end services behind one API. For a simple integration between two systems, REST is usually the more practical choice. In integration work we often consume GraphQL APIs too; Shopify's Admin API is GraphQL-first, for example. See our GraphQL development, custom API development and Shopify integration.

Frequently Asked Questions about GraphQL

Is GraphQL a database?

No. GraphQL is a query language for APIs. Behind a GraphQL API can be any database, other APIs or a combination of services.

Does GraphQL replace REST?

Not necessarily. Many organisations use both: REST for simple integrations and webhooks, GraphQL for flexible data access by front-ends. They solve partly different problems.

Is GraphQL faster than REST?

It can be, because fewer requests and less data cross the network. On the server side, GraphQL can actually be slower if queries are not limited and resolvers are not optimised.

Which languages support GraphQL?

Practically all of them: there are mature GraphQL libraries for JavaScript/TypeScript, Python, C#, Java, Go, PHP and Rust.