GraphQL
GraphQL is an API query language and runtime that lets clients request exactly the fields they need from a single, strongly typed endpoint.
GraphQL is a specification, originally created at Facebook, for building APIs where the client declares the shape of the data it wants. A single endpoint accepts a query, and the server returns a JSON document matching that query's structure.
How It Works
A GraphQL service exposes a strongly typed schema that describes the available types, fields, and operations. Clients send three kinds of operations: queries (reads), mutations (writes), and subscriptions (real-time streams). The server validates each request against the schema, then uses resolver functions to fetch each field from databases, services, or other APIs.
Because the client specifies the fields, one request can replace several REST calls. The response contains no more and no less than what was asked. Introspection lets tooling discover the schema automatically, which powers editors, documentation, and code generation.
Why It Matters
GraphQL addresses two common REST problems: over-fetching, where an endpoint returns more than the screen needs, and under-fetching, where a screen must call many endpoints. This makes it attractive for mobile clients and rich front ends that aggregate data from multiple sources.
The trade-offs are real. Caching is harder than with REST because most requests are POSTs to one URL. Arbitrary nested queries can be expensive, so teams add query depth limits, cost analysis, and persisted queries. The server also takes on more complexity in resolver design and the N+1 query problem, usually solved with batching loaders.
GraphQL suits aggregation layers and product APIs with diverse clients. Simple CRUD services or cache-heavy public APIs often stay simpler with REST.
Related Terms
GraphQL is frequently compared with REST and gRPC. It returns JSON and can sit behind an API gateway alongside other styles.