GraphQL
A Query Language for your API
schema {
query: Query
mutation: Mutation
}
type Query {
tasks: [Task]!
}
type Mutation {
addTask(text: String!): [Task]!
}
type Task {
id: ID
text: String!
finished: Boolean,
assignee: User
}
type User {
id: ID
name: String!
}
query getUnfinishedTasks {
todos(finished: false) {
text
}
}
{
"data": {
"todos": [{
"text": "Continue procrastinating",
"text": "Drink more beer",
"text": "Do something grand"
}]
}
}
GraphQL Query
JSON Response
Server
Data Sources
App
Clients
GraphQL Queries
JSON Payload
Database
Rest API
???
curl -XPOST -H "Content-Type:application/graphql" -d \
'query { tasks }' http://localhost:3000/graphql
{
"data": {
"tasks": [
{
"text": "Eat pizza"
}
]
}
}
Relay