GraphQL is a query language for APIs and a runtime for fulfilling those queries against existing data. Rather than exposing many fixed endpoints that each return a predetermined shape of data, a GraphQL service exposes a single endpoint and a strongly typed schema. Clients send a query describing exactly which fields they want, and the server returns a response matching that shape, no more and no less. This solves the over-fetching and under-fetching problems that plague many REST APIs, where a client must call several endpoints or receive large payloads to assemble the data a screen needs.
GraphQL was developed internally at Facebook starting in 2012 to power the data needs of its mobile applications, and it was publicly announced and open-sourced in 2015. The original announcement on graphql.org introduced it as “a data query language” and described how Facebook’s mobile apps had been driven by GraphQL since 2012, presenting both the query language and the type system that underpins it.
At the heart of GraphQL is its schema, written in the Schema Definition Language. The schema defines object types, the fields on those types, and the relationships between them, along with special root types for queries, mutations that change data, and subscriptions that stream live updates. Because the schema is strongly typed and introspectable, tools can validate queries ahead of time, generate documentation automatically, and provide rich editor support, and clients can discover the full capabilities of an API by querying the schema itself.
The language and execution semantics are defined by the GraphQL specification, maintained by the GraphQL Foundation under the Linux Foundation. The October 2021 edition was the first full specification edition ratified by the Foundation, building on earlier working drafts that began with the July 2015 release. The specification deliberately describes the query language, type system, validation rules, and execution algorithm while leaving transport, storage, and implementation language open, so GraphQL can sit in front of databases, microservices, and other APIs alike.
GraphQL did not replace REST so much as offer an alternative model suited to client-driven, graph-shaped data. It became especially popular for applications with many distinct front-end clients and complex, interconnected data, where the ability to fetch precisely the required fields in one round trip is valuable. A large ecosystem of clients and servers grew around it, with Apollo emerging as one of the most widely used implementations, and the federation pattern extending GraphQL to compose many services into a single graph.