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
GitHub API v4: GitHub offers a GraphQL API alongside REST v3 so you can load repo, issues, PRs and commits in one query.
Shopify Storefront API: Merchants use GraphQL to plug shop data (products, collections, checkout) into custom frontends.
Headless CMS: Contentful and Strapi expose GraphQL so frontends request only the fields needed for a page.
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?
How do I prevent N+1 in GraphQL?
What does a GraphQL API cost to build?
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.