Last active
October 11, 2016 10:42
-
-
Save gsans/d857b0951077bdbbabd968e0431d97fe to your computer and use it in GitHub Desktop.
GraphQL Queries and Mutations by @gerardsans
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#===================================================== | |
# | |
# GraphQL Queries and Mutations by @gerardsans | |
# | |
#===================================================== | |
schema { | |
query: Query, | |
mutation: Mutation | |
} | |
type Query { | |
allTodoes(skip: Int, take: Int): [Todo!]! | |
} | |
type Mutation { | |
createTodo(text: String!, complete: Boolean!): Todo | |
updateTodo(id: ID!, text: String, complete: Boolean): Todo | |
} | |
type Todo { | |
id: ID! | |
text: String! | |
complete: Boolean! | |
} | |
#===================================================== | |
# 1 Basic query | |
{ | |
allTodoes { | |
id | |
text | |
complete | |
} | |
} | |
#===================================================== | |
# 2 Named query | |
query todos { | |
allTodoes { | |
id | |
text | |
complete | |
} | |
} | |
#===================================================== | |
# 3 Fragments | |
query todos { | |
allTodoes { | |
...info | |
} | |
} | |
fragment info on Todo { | |
id | |
text | |
...state | |
} | |
fragment state on Todo { | |
complete | |
} | |
#===================================================== | |
# 4 Using alias | |
query todos { | |
todos: allTodoes { | |
...info | |
} | |
} | |
fragment info on Todo { | |
guid: id | |
title: text | |
...state | |
} | |
fragment state on Todo { | |
completed: complete | |
} | |
#===================================================== | |
# 5 Multiple queries | |
query todos { | |
todos: allTodoes { | |
id | |
text | |
complete | |
} | |
activeTodos: allTodoes(filter: { complete: false }) { | |
id | |
text | |
complete | |
} | |
} | |
#===================================================== | |
# 6 Query Variables | |
query todos($filter: TodoFilter) { | |
todos: allTodoes { | |
id | |
text | |
complete | |
} | |
activeTodos: allTodoes(filter: $filter) { | |
id | |
text | |
complete | |
} | |
} | |
-------------------------------------------------------- | |
{ | |
"filter" : { | |
"complete": true | |
} | |
} | |
#===================================================== | |
# 7 Add todo Mutation | |
mutation addTodo($text: String!) { | |
createTodo(text: $text, complete: false) { | |
id | |
} | |
} | |
-------------------------------------------------------- | |
{ | |
"text": "learn gql" | |
} | |
#===================================================== | |
# 8 Toggle todo Mutation | |
mutation toggleTodo($id: ID!, $complete: Boolean!) { | |
updateTodo(id: $id, complete: $complete) { | |
id | |
complete | |
} | |
} | |
-------------------------------------------------------- | |
{ | |
"id": "ADD_ID", | |
"complete": false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment