What is GraphQL

GraphQL is an API specification, which enables clients (such as the website in the browser, or a mobile app) to specify exactly what data they need, and the server implementing the API will retrieve exactly that.

A GraphQL query looks like this:

query {
posts {
id
title
content
author {
id
name
}
}
}

The response from the server is in JSON format, containing the data in the same shape as the query. It looks like this:

{
"data": {
"posts": [
{
"id": 1,
"title": "Hello world",
"content": "<p>How are you doing?</p>",
"author": {
"id": 1,
"name": "Leo"
}
},
{
"id": 2,
"title": "Scheduled post",
"content": "<p>This post is scheduled to be published in the future.</p>",
"author": {
"id": 2,
"name": "Markus"
}
},
{
"id": 3,
"title": "Lorem ipsum",
"content": "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>",
"author": {
"id": 3,
"name": "Socrates"
}
}
]
}
}

GraphQL servers can also "mutate" (i.e. create and update) data. In this case, the operation keyword query must be replaced with mutation:

mutation {
createPost(title: "New post", content: "Lorem ipsum dolor sit amet") {
id
status
}
}

There are many resources concerning GraphQL. We recommend checking out graphql.org and howtographql.com.