A query language for your API
(and what it means for Content Management)
Alternative to REST and SOAP
A specification created by Facebook
GraphQL servers in many languages (Node, PHP, etc)
Used by the new Github API, Pinterest, Shopify, ...
Smart schema, smart clients
Strict typing, self-documenting
Inline "resources" in a single call
GET /api/v1/currentUser GET /api/v1/menu GET /api/v1/file/?parent=0 GET /api/v1/file/99/history GET /api/v1/file/99/usage GET /api/v1/file/99/actions
GET /api/v1/config GET /api/v1/file/ ?parent=0 &include=id,title,url,history,related,actions
GET /api/v1/config GET /api/v1/file/ ?parent=0 &include=id,title,url,history,related,actions &fields=history.date,history.version
GET /api/v1/currentUser
GET /api/v1/menu
GET /api/v1/file/
?parent=0
&include=history,related,actions
&fields=history.date,history.version
&history.limit=5
Text
Text
Text
type File {
id: ID!
title: String
url: String
size: Int
}
query ReadFiles() {
readFiles(limit:20) {
id
title
url
}
}
[
{
"id": 98,
"title": "otto",
"url": "otto.jpg"
},
{
"id": 99,
"title": "john",
"url": "john.doc"
}
]
Text
Text
query ReadFiles() {
readFiles(limit:20) {
id
title
url
related {
id
title
url
}
history(limit: 5) {
version
date
}
actions {
name
}
}
}
[
{
"id": 98,
"title": "otto",
"url": "otto.jpg",
"related": [
{
"id": 1,
"title": "otherfile",
"url": "otherfile.jpg"
}
],
"history": [ /* ... */ ],
"actions": [ /* ... */ ]
},
/* ... */
]
query ReadFiles() {
readFiles(limit:20) {
id
title
url
related {
id
title
url
}
history(limit: 5) {
version
date
}
actions {
name
}
}
}
[
{
"id": 98,
"title": "otto",
"url": "otto.jpg",
"related": [
{
"id": 1,
"title": "otherfile",
"url": "otherfile.jpg"
}
],
"history": [ /* ... */ ],
"actions": [ /* ... */ ]
},
/* ... */
]
type File {
id: ID!
title: String
url: String
size: Int
history: [FileVersion]
related: [File]
actions: [ContentAction]
}
twitter.com/chillu
silverstripe.org/4
github.com/silverstripe/silverstripe-graphql
graphql.org