GraphQL
Definition
Query language and runtime for APIs that allows clients to request specific data, optimizing data retrieval and reducing over-fetching of information.
Use Cases
- GitHub: Provide a flexible API for developers to query repository, issue, pull request, and user data without multiple REST calls. — GitHub offers a public GraphQL API (v4) where clients define exactly which fields they need. The GraphQL layer resolves fields by fetching from GitHub’s underlying services and data stores, enabling clients to compose queries for complex UI screens. (Developers can reduce over-fetching and under-fetching compared to many REST endpoints, often lowering the number of network requests needed to build dashboards and integrations.)
- Shopify: Enable storefronts and apps to retrieve precisely the product, inventory, and order data needed for fast commerce experiences. — Shopify provides GraphQL APIs (notably for Admin and Storefront use cases). Clients query for specific fields and use connections/pagination patterns to efficiently traverse large catalogs and order histories. (Apps and storefronts can optimize payload sizes and request patterns, improving perceived performance and making it easier to evolve client features without waiting for new server endpoints.)
- Netflix: Support diverse device clients (TVs, phones, web) that need different shapes of data for the same screen. — Netflix has publicly discussed using GraphQL in parts of its architecture to help clients request tailored data. A GraphQL layer can aggregate data from multiple backend services and return device-specific responses. (Client teams can iterate faster by requesting only what each device UI needs, reducing unnecessary data transfer and simplifying client-side data orchestration.)
Provider Equivalents
- AWS: AWS AppSync
- Azure: Azure API Management
- GCP: Apigee API Management
Frequently Asked Questions
- What's the difference between GraphQL and REST?
- REST typically exposes multiple endpoints (for example, /users and /users/{id}/orders), and each endpoint returns a fixed response shape. GraphQL usually exposes a single endpoint where the client specifies exactly which fields it wants. This can reduce over-fetching (getting too much data) and under-fetching (needing multiple calls to assemble a screen), but it also requires careful schema design, authorization, and query controls.
- When should I use GraphQL?
- Use GraphQL when clients need flexible data shapes, especially for mobile apps, complex UIs, or multiple frontends (web + iOS + Android) that need different fields. It’s also helpful when you want a strongly typed API contract (schema) and good developer tooling. Avoid or be cautious if your API is very simple, if you can’t invest in schema governance and security controls, or if caching and CDN-friendly patterns are your top priority and you don’t have a plan for GraphQL caching.
- How much does GraphQL cost?
- GraphQL itself is free (it’s a specification and many server libraries are open source). Costs come from how you run it: compute (containers/serverless), networking, and operational tooling (monitoring, logging, tracing). If you use a managed service like AWS AppSync, pricing is based on service-specific factors such as the number of API operations/requests and any connected data sources. If you place GraphQL behind an API management product, you may also pay for gateway capacity, requests, and analytics features.
Category: software
Difficulty: intermediate
Related Terms
See Also