Skip to main content
Basics

GraphQL

Query language for APIs developed by Facebook/Meta; enables precise data requests and reduces over- and under-fetching compared to REST.

GraphQL solves a core REST problem: clients get either too much data (overfetching) or too little (underfetching, multiple requests). With GraphQL the client requests exactly the data it needs – no more, no less. Since Facebook open-sourced it in 2015, GraphQL is used by GitHub, Shopify, Twitter and thousands of others.

What is GraphQL?

GraphQL is a query language and runtime for APIs, developed by Facebook/Meta and released as open source in 2015. Unlike REST with fixed endpoints and response shapes, GraphQL has a single endpoint where the client defines the exact shape of the query. A GraphQL schema defines types (User, Product, Order), their fields and relationships. Clients send queries (read), mutations (write) and subscriptions (real-time). The spec is language-agnostic; implementations exist for JavaScript, Python, Java, Go and more.

How does GraphQL work?

The client sends a GraphQL query as JSON, e.g. { user(id: 42) { name, email, orders { total } } }. The server validates against the schema, runs resolver functions for each requested field and returns exactly that structure. The schema defines types (e.g. type User { id: ID!, name: String!, orders: [Order!]! }) and the server implements resolvers that load data from DBs, APIs or other sources. DataLoader batches and caches DB calls to avoid N+1. Subscriptions use WebSockets for real-time updates.

Practical Examples

1

GitHub API v4: GitHub offers a GraphQL API alongside REST v3 so you can load repo, issues, PRs and commits in one query.

2

Shopify Storefront API: Merchants use GraphQL to plug shop data (products, collections, checkout) into custom frontends.

3

Headless CMS: Contentful and Strapi expose GraphQL so frontends request only the fields needed for a page.

4

Mobile app backend: The app loads user data, recent orders and recommendations in one GraphQL query instead of three REST calls.

Typical Use Cases

Mobile apps: Minimal data transfer via precise queries – important on slow connections

Microservices gateway: GraphQL as a single API layer in front of multiple backends

E-commerce: Flexible product queries with attributes, variants and relations

Content delivery: Headless CMS with GraphQL for flexible frontends

Dashboards and analytics: Complex nested queries for reporting UIs

Advantages and Disadvantages

Advantages

  • No over/underfetching: Client gets exactly the data it needs
  • Single endpoint: All data from one URL, no endpoint explosion
  • Strong typing: Schema defines types and relations – self-documenting
  • Evolving API: Add fields without new versions; clients choose what they use
  • Real-time: Subscriptions for live updates

Disadvantages

  • Caching: REST’s simple URL-based caching is easier; GraphQL needs careful cache strategy
  • Complexity: Schema design and N+1 avoidance need experience
  • Overkill for simple CRUD: REST can be enough for basic APIs
  • Query cost: Deep or broad queries can be expensive on the server

Frequently Asked Questions about GraphQL

GraphQL or REST?

Use GraphQL when clients need varying data shapes, you have many clients (web, mobile, partners) or complex nested data. Use REST when the API is simple, caching by URL is important or the team has no GraphQL experience. Many systems use both.

How do I prevent N+1 in GraphQL?

Use batching (e.g. DataLoader): collect all requested IDs in one tick, load in one or few DB queries, then resolve. Without batching, each list item can trigger its own query (N+1). DataLoader also caches per request so the same ID isn’t loaded twice.

What does a GraphQL API cost to build?

A simple GraphQL API (5–10 types, basic auth): about €10,000–25,000. With subscriptions, complex schema and optimization: €25,000–60,000. Enterprise with federation, multiple backends and governance: €60,000–150,000. Ongoing hosting and maintenance are extra.

Related Terms

Want to use GraphQL in your project?

We are happy to advise you on GraphQL and find the optimal solution for your requirements. Benefit from our experience across over 200 projects.

Next Step

Questions about the topic? We're happy to help.

Our experts are available for in-depth conversations – no strings attached.

30 min strategy call – 100% free & non-binding

What is GraphQL? API Query Language Explained