


We use cookies to improve your experience
We use essential cookies to make our site work. With your consent, we may also use non-essential cookies to improve user experience.
Definition
GraphQL is a query language for APIs developed by Facebook (now Meta). Unlike REST, where the server defines fixed endpoints, GraphQL lets clients request exactly the data they need in a single query, reducing over-fetching and under-fetching.
In a REST API, each resource has its own endpoint (/users, /posts, /comments), and the server decides what data each endpoint returns. A mobile app showing a user profile with their posts might need three separate requests. GraphQL replaces this with a single endpoint that accepts a query describing exactly which fields to return. The client asks for user name, email, and the titles of their last 5 posts — and gets exactly that, nothing more.
Every GraphQL API is defined by a schema — a strongly typed description of available data types, fields, and relationships. This schema serves as a contract and documentation simultaneously. Tools like GraphiQL and Apollo Studio let developers explore the schema interactively, autocomplete queries, and validate them before sending. The type system catches errors at development time rather than at runtime.
GraphQL shines when clients have diverse data needs (mobile vs. desktop), when network performance matters (fewer round trips), or when the data graph is highly interconnected. However, it introduces complexity: caching is harder than with REST, query complexity must be bounded to prevent abuse, and the learning curve is steeper. For simple CRUD APIs with few clients, REST is often simpler and sufficient.