---
title: GraphQL
slug: graphql
qid: 
snapshot: enwiki-001372636557
content_hash: 
license: CC BY-SA 4.0
source: https://en.wikipedia.org/w/index.php?oldid=1372636557
tags: [11060667, 22920259, 22959635, 23117742, 23603337, 26220375, 26748027, 28493675, 29176367, 31127017, 31128808, 33410312, 61223397]
---

# GraphQL

> [!note] Provenance
> Snapshot `enwiki-001372636557` · content root `…`
> Derived from <https://en.wikipedia.org/w/index.php?oldid=1372636557> · Licensed CC BY-SA 4.0

GraphQL is a data query and manipulation language that allows specifying what data is to be retrieved ("declarative data fetching") or modified. A GraphQL server can process a client query using data from separate sources and present the results in a unified graph. The language is not tied to any specific database or storage engine. There are several open-source runtime engines for GraphQL.

GraphQL is a data query and manipulation language that allows specifying what data is to be retrieved ("declarative data fetching") or modified. A GraphQL server can process a client query using data from separate sources and present the results in a unified graph. The language is not tied to any specific database or storage engine. There are several open-source runtime engines for GraphQL. Fields are defined as nullable by default, and a trailing exclamation mark can be used to make a field non-nullable (required). A field can be defined as a list by wrapping the field's type in square brackets (for example, ). type Query { currentUser: User } type User { id: ID! name: String! } A GraphQL query defines the exact shape of the data needed by the client. query CurrentUser { currentUser { name age } } Once validated and executed by the GraphQL server, the data is returned in the same shape. { "currentUser": { "name": "John Doe", "age": 23 } } mutation CreateUser($name: String!, $age: Int!) { createUser(userName: $name, age: $age) { name age } } The variables are passed as an object with fields that match the variable names in the mutation. { "name": "Han Solo", "age": 42 } Once the operation is complete, the GraphQL server will return data matching the shape defined by the mutation. { "data": { "createUser": { "name": "Han Solo", "age": 42 } } } GraphQL also supports live updates sent from the server to client in an operation called a subscription. Again, the client defines the shape of the data that it needs whenever an update is made. subscription { newPerson { name age } } When a mutation is made through the GraphQL server that updates the associated field, data is sent to all subscribed clients in the format setup through the subscription. { "newPerson": { "name": "Jane", "age": 23 } }
