GraphQL is an open-source data
query and
manipulation language for
API
An application programming interface (API) is a way for two or more computer programs to communicate with each other. It is a type of software Interface (computing), interface, offering a service to other pieces of software. A document or standa ...
s, and a runtime for fulfilling queries with existing data.
GraphQL was developed internally by
Facebook
Facebook is an online social media and social networking service owned by American company Meta Platforms. Founded in 2004 by Mark Zuckerberg with fellow Harvard College students and roommates Eduardo Saverin, Andrew McCollum, Dustin M ...
(now Meta) in 2012 before being publicly released in 2015. On 7 November 2018, the GraphQL project was moved from Facebook to the newly established GraphQL Foundation, hosted by the non-profit
Linux Foundation
The Linux Foundation (LF) is a non-profit technology consortium founded in 2000 as a merger between Open Source Development Labs and the Free Standards Group to standardize Linux, support its growth, and promote its commercial adoption. Additi ...
. Since 2012, GraphQL's rise has closely followed the adoption timeline as set out by Lee Byron, GraphQL's creator. Byron's goal is to make GraphQL omnipresent across web platforms.
GraphQL provides an approach to developing web APIs and has been compared and contrasted with
REST
Rest or REST may refer to:
Relief from activity
* Sleep
** Bed rest
* Kneeling
* Lying (position)
* Sitting
* Squatting position
Structural support
* Structural support
** Rest (cue sports)
** Armrest
** Headrest
** Footrest
Arts and entert ...
and other
web service architectures. It allows clients to define the structure of the data required, and the same structure of the data is returned from the server. This prevents excessively large amounts of data from being returned, but can impede
web caching
A Web cache (or HTTP cache) is a system for optimizing the World Wide Web. It is implemented both client-side and server-side. The caching of multimedias and other files can result in less overall delay when browsing the Web.
Parts of the syste ...
of query results.
The flexibility and richness of the query language also adds complexity that may not be worthwhile for simple APIs.
Despite the name, GraphQL does not provide the richness of graph operations that one might find in a full-fledged
graph
Graph may refer to:
Mathematics
*Graph (discrete mathematics), a structure made of vertices and edges
**Graph theory, the study of such graphs and their properties
*Graph (topology), a topological space resembling a graph in the sense of discre ...
query language such as
SPARQL
SPARQL (pronounced "sparkle" , a recursive acronym for SPARQL Protocol and RDF Query Language) is an RDF query language—that is, a semantic query language for databases—able to retrieve and manipulate data stored in Resource Description F ...
, or even in
dialects of SQL that support
transitive closure
In mathematics, the transitive closure of a binary relation on a set is the smallest relation on that contains and is transitive. For finite sets, "smallest" can be taken in its usual sense, of having the fewest related pairs; for infinite s ...
.
For example, a GraphQL interface that reports the parents of an individual cannot return, in a single query, the set of all their ancestors.
GraphQL consists of a type system, query language and execution semantics, static validation, and
type introspection
In computing, type introspection is the ability of a program to ''examine'' the Data type, type or properties of an Object (computer science), object
at Run time (program lifecycle phase), runtime.
Some programming languages possess this capability ...
.
It supports reading, writing (mutating), and subscribing to changes to data (realtime updates – most commonly implemented using
Websockets
WebSocket is a computer communications protocol, providing full-duplex communication channels over a single TCP connection. The WebSocket protocol was standardized by the IETF as in 2011. The current API specification allowing web applications ...
). GraphQL servers are available for multiple languages. The result of a single query is returned in
JSON
JSON (JavaScript Object Notation, pronounced ; also ) is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays (or other ser ...
format.
On 9 February 2018, the GraphQL Schema Definition Language (SDL) became part of the specification.
Example
GET
Get or GET may refer to:
* Get (animal), the offspring of an animal
* Get (divorce document), in Jewish religious law
* GET (HTTP), a type of HTTP request
* "Get" (song), by the Groggers
* Georgia Time, used in the Republic of Georgia
* Get AS, a ...
request:
Response:
Testing
GraphQL APIs can be tested by triggering different requests at the API endpoint, and verifying the correctness of the response. This may be done manually by developers, or automated with testing tools. Tests may also be generated automatically. For example, a request triggered by an existing test case can be mutated to produce a variant, and new requests may be produced through search-based techniques. GraphQL requests arriving at the API endpoint in production may also be used to generate test cases that detect errors in the implementation of the schema.
See also
*
Query by Example
Query by Example (QBE) is a database query language for relational databases. It was devised by Moshé M. Zloof at IBM Research during the mid-1970s, in parallel to the development of SQL. It is the first graphical query language, using visual t ...
*
OpenAPI Specification
The OpenAPI Specification, previously known as the Swagger Specification, is a specification for a machine-readable interface definition language for describing, producing, consuming and visualizing RESTful web services. Previously part of the S ...
*
Microservices
A microservice architecture – a variant of the service-oriented architecture structural style – is an architectural pattern that arranges an application as a collection of loosely-coupled, fine-grained services, communicating through lightw ...
References
External links
*
*
Query languages
Data modeling languages
{{software-stub