GraphQL
≈ 2 min read
Names in other languages
No names in other languages are held for this entry yet.
Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.
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 } }
Text derived from https://en.wikipedia.org/w/index.php?oldid=1372636557 under CC BY-SA 4.0; modifications have been made.