What is GraphQL? logo

What is GraphQL?

Free

A syntax that describes how to ask for data

FreeFree tier
Type
Open Source

About What is GraphQL?

GraphQL is a syntax that describes how to ask for data, typically used to load data from a server to a client. Developed by Facebook, it addresses limitations of traditional REST APIs by allowing clients to specify exactly what data they need, making it easier to aggregate data from multiple sources, and using a strong type system to describe data. A GraphQL API is organized around three main building blocks: schema, queries, and resolvers. Queries support nested fields and can point to arrays, enabling efficient data fetching. GraphQL establishes a single 'smart' endpoint that receives client requests and fetches the necessary data from one or more data sources, acting as a personal assistant for data retrieval.

Key Features

Client can specify exactly what data it needs
Easily aggregates data from multiple sources
Uses a type system to describe data
Supports nested fields in queries
Single 'smart' endpoint instead of multiple REST endpoints
Organized around schema, queries, and resolvers

Pros & Cons

Pros
  • Eliminates over-fetching by letting clients request only needed data
  • Simplifies data aggregation from multiple sources
  • Strongly typed schemas improve API reliability and tooling
  • Nested queries reduce the number of API calls
Cons
  • Learning curve for understanding schema design and resolvers
  • May be overkill for simple CRUD applications
  • Caching can be more complex compared to REST

Best For

Loading data from a server to a client with precise data requirementsAggregating data from multiple databases (e.g., MySQL and Redis) into a single responseBuilding APIs that need to serve different clients (web, mobile) with varying data needsReplacing complex REST API setups with a more efficient query language

FAQ

What is GraphQL?
GraphQL is a syntax that describes how to ask for data, typically used to load data from a server to a client. It allows clients to specify exactly what data they need and aggregates data from multiple sources using a strong type system.
How does GraphQL differ from REST?
Instead of having multiple 'dumb' endpoints like in REST, GraphQL uses a single 'smart' endpoint that can take complex queries and shape the data output to exactly what the client requires, reducing over-fetching and under-fetching.