Uma linguagem de consulta para APIs.

type Post {
title: String!
author: Person!
}
type Person {
name: String!
age: Int!
posts: [Post!]!
}
Query
{
allPersons {
name
}
}
Resposta
{
"allPersons": [
{ "name": "Johnny" },
{ "name": "Sarah" },
{ "name": "Alice" }
]
}
O cliente pede exatamente os campos que quer — nada mais, nada menos.
Com argumento
{
allPersons(last: 2) {
name
}
}
Campos aninhados
{
allPersons {
name
age
posts {
title
}
}
}
mutation
mutation {
createPerson(name: "Bob", age: 36) {
name
age
}
}
Assim como as queries, a mutation já devolve os campos pedidos do registro criado.
Comunicação bidirecional e em tempo real.




GET /chat HTTP/1.1
Host: server.example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==
Sec-WebSocket-Protocol: chat, superchat
Sec-WebSocket-Version: 13
Origin: http://example.com
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=
Sec-WebSocket-Protocol: chat
O Upgrade: websocket pede pra trocar de protocolo; o servidor confirma com 101 Switching Protocols — a partir daí, é WebSocket.
YouTube
What Is GraphQL? — ByteByteGo
youtube.com/watch?v=yWzKJPw_VzM
YouTube
WebSockets — Eduardo Mendes
youtube.com/watch?v=EqFzY8dBWHs