Created
June 6, 2017 22:13
-
-
Save dmitry-saritasa/b45a0857622f49179ee3dc73c2265d68 to your computer and use it in GitHub Desktop.
GraphQL - Basic queries 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 all { | |
allFilms { | |
films { | |
episodeID | |
created | |
id | |
title | |
} | |
} | |
} | |
# --------------------------------------------- | |
# Let's add some references | |
# --------------------------------------------- | |
query all { | |
allFilms { | |
films { | |
episodeID | |
created | |
id | |
title | |
planetConnection { | |
planets { | |
id | |
diameter | |
name | |
} | |
} | |
} | |
} | |
} | |
# --------------------------------------------- | |
# Let's add some pagination | |
# --------------------------------------------- | |
query all { | |
allFilms (first: 3) { | |
totalCount | |
pageInfo { | |
hasNextPage | |
hasPreviousPage | |
startCursor | |
endCursor | |
} | |
films { | |
episodeID | |
created | |
id | |
title | |
planetConnection { | |
planets { | |
id | |
diameter | |
name | |
} | |
} | |
} | |
} | |
} | |
# --------------------------------------------- | |
# Continuous pagination using 'after' keyword | |
# --------------------------------------------- | |
query all { | |
allFilms (first: 3 after:"YXJyYXljb25uZWN0aW9uOjI=") { | |
totalCount | |
pageInfo { | |
hasNextPage | |
hasPreviousPage | |
startCursor | |
endCursor | |
} | |
films { | |
episodeID | |
created | |
id | |
title | |
planetConnection { | |
planets { | |
id | |
diameter | |
name | |
} | |
} | |
} | |
} | |
} | |
# --------------------------------------------- | |
# Let's union some data | |
# this is perfect example how to avoid | |
# multiple queries to different REST API | |
# endpoints representing different entities | |
# so below we combine two different data | |
# sets - people and films together in a single | |
# graphql query | |
# --------------------------------------------- | |
query all { | |
allPeople { | |
people { | |
id | |
name | |
homeworld { | |
name | |
} | |
species { | |
name | |
averageLifespan | |
} | |
} | |
} | |
allFilms (first: 3 after:"YXJyYXljb25uZWN0aW9uOjI=") { | |
totalCount | |
pageInfo { | |
hasNextPage | |
hasPreviousPage | |
startCursor | |
endCursor | |
} | |
films { | |
episodeID | |
created | |
id | |
title | |
planetConnection (first:1) { | |
planets { | |
id | |
diameter | |
name | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment