Created
June 6, 2017 22:18
-
-
Save dmitry-saritasa/11d94d4ffc3c1cd3f390df68d419b78c to your computer and use it in GitHub Desktop.
GraphQL - Parameterization example
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
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