Glossary termQuery language

GraphQL

Query language and runtime for APIs that lets clients request exactly the data they need from a server in a single, strongly typed query.

GraphQL is a query language for APIs and a specification for servers that answer those queries. A GraphQL service publishes a schema, a typed description of the data and operations it offers. Clients send queries that mirror the shape of the response they want: a request might ask for a user's name and the titles of their five most recent posts and receive exactly those fields, nested the same way, in JSON. Mutations change data, and subscriptions deliver updates in real time, often over WebSocket connections.

Facebook developed GraphQL internally in 2012 to serve its mobile apps, which needed to fetch complex, nested data efficiently over slow networks, and released it publicly in 2015. In 2018 the project moved to the GraphQL Foundation, hosted by the Linux Foundation. Compared with REST, where each resource has its own URL and the server decides what each response contains, GraphQL typically exposes a single endpoint and lets the client decide. Implementations exist for most languages, and companies including GitHub and Shopify offer public GraphQL APIs.

GraphQL addresses two common REST problems: over-fetching, where responses include fields the client does not need, and under-fetching, where a screen must call several endpoints to assemble its data. The schema also provides self-documentation and enables tooling such as autocompletion and type checking in clients. The flexibility has costs. Servers must guard against expensive or deeply nested queries that could overload them; HTTP caching is harder when every request goes to one endpoint; and a poorly designed resolver layer can trigger many redundant database queries. For simple APIs, REST is often easier.

Key points

  • GraphQL clients describe the exact shape of the data they want, and the server returns precisely that.
  • A typed schema defines the available data and operations, enabling documentation and tooling.
  • Facebook built GraphQL in 2012, released it in 2015 and moved it to the GraphQL Foundation in 2018.
  • Servers must limit query depth and cost, and caching is harder than with resource-based REST APIs.

Related entries

Glossary term

API

Programming

Defined set of rules and interfaces through which one piece of software can request services or data from another without knowing its internals.

Glossary term

REST API

ProgrammingAI

Web interface that follows the REST architectural style, exposing resources at URLs that clients manipulate with stateless HTTP requests.

Glossary term

JSON

Programming

Lightweight, text-based data interchange format that represents structured data as nested objects and arrays, derived from JavaScript syntax.

Glossary term

WebSocket

Programming

Communication protocol that provides a persistent, two-way channel between a web browser and a server over a single TCP connection.

Glossary term

HTTP

ProgrammingCybersecurity

Stateless request-response protocol that web browsers, servers and other clients use to request and transfer resources such as web pages and data.

Organization

Nonprofit consortium that supports the Linux kernel and hosts many major open-source projects, foundations, events and training programs.

Glossary term

Web application that loads a single HTML page and then updates its content with JavaScript instead of loading fresh pages from the server.

Glossary term

Database

Programming

Organized collection of structured data stored electronically and managed by software that lets users store, query and update it reliably.