Skip to content

Instantly share code, notes, and snippets.

@dmitry-saritasa
Created June 6, 2017 22:20
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/2d74315852128a1cc4af58e04ca2a638 to your computer and use it in GitHub Desktop.
Save dmitry-saritasa/2d74315852128a1cc4af58e04ca2a638 to your computer and use it in GitHub Desktop.
GraphQL Fragments
Test in : http://graphql.org/swapi-graphql
# ---------------------------------------------
# Fragment based query
# ---------------------------------------------
query details($episode: ID, $withStarship: Boolean = false) {
film(id: $episode) {
id
title
characterConnection {
characters {
id
name
starshipConnection {
starships {
...starshipDetails
}
}
}
}
starshipConnection @include(if: $withStarship) {
starships {
...starshipDetails
}
}
}
}
fragment starshipDetails on Starship {
id
name
pilotConnection {
pilots {
id
name
homeworld {
id
}
}
}
}
# Add below in variables section of graphiql
{
"episode": "ZmlsbXM6MQ==",
"withStarship": true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment