Skip to content

Instantly share code, notes, and snippets.

@dmitry-saritasa
Created June 6, 2017 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitry-saritasa/11d94d4ffc3c1cd3f390df68d419b78c to your computer and use it in GitHub Desktop.
Save dmitry-saritasa/11d94d4ffc3c1cd3f390df68d419b78c to your computer and use it in GitHub Desktop.
GraphQL - Parameterization example
Test in : http://graphql.org/swapi-graphql
# ---------------------------------------------
# Basic query
# ---------------------------------------------
query details ($episode: ID $withStarship: Boolean = false){
film (id: $episode) {
id
title
starshipConnection @include(if: $withStarship) {
starships {
id
}
}
}
}
# Add below in variables section of graphiql
{
"episode": "ZmlsbXM6MQ==",
"withStarship": true
}
# ---------------------------------------------
# More complex query
# ---------------------------------------------
query details ($episode: ID $withStarship: Boolean = false){
film (id: $episode) {
id
title
characterConnection {
characters {
id
starshipConnection {
starships {
id
}
}
}
}
starshipConnection @include(if: $withStarship) {
starships {
id
pilotConnection {
pilots {
id
}
}
}
edges {
node {
id
name
pilotConnection {
edges {
node {
id
name
gender
species {
id
name
}
}
}
}
}
}
}
}
}
# Add below in variables section of graphiql
{
"episode": "ZmlsbXM6MQ==",
"withStarship": false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment