Basic GraphQL TODO, for study library graphql subscription
git clone https://github.com/jdgabriel/graphql-ToDo
cd graphql-ToDo
yarn install
query all {
todos {
id
task
complete
}
}
{
"data": {
"todos": [
{
"id": "1",
"task": "Read About graphql",
"complete": true
}
]
}
}
mutation new {
newTodo(data: { task: "Buy Coffe", complete: false }) {
mutation
node {
id
task
complete
}
}
}
{
"data": {
"newTodo": {
"mutation": "CREATED",
"node": {
"id": "2",
"task": "Buy Coffe",
"complete": false
}
}
}
}
Use id field for update Todo
mutation edit {
editTodo(
fields: { task: "Bath in the cat", complete: true }
where: { id: "1" }
) {
mutation
node {
id
task
complete
}
}
}
{
"data": {
"editTodo": {
"mutation": "UPDATED",
"node": {
"id": "2",
"task": "Bath in the cat",
"complete": true
}
}
}
}
Use id field for update Todo
mutation remove {
removeTodo(where: {id: "2"})
}
{
"data": {
"removeTodo": true
}
}
Subscriptions are based on three nodes
- CREATED
- UPDATED
- REMOVED
subscription {
todo(mutation: UPDATED) {
mutation
node {
id
task
complete
}
}
}
{
"data": {
"todo": {
"mutation": "UPDATED",
"node": [...]
}
}
}
Gabriel Duarte