From d74edcc0b6acb7eeea125819ab37f535cb12b3b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alessandro=20Pezz=C3=A8?= Date: Sat, 10 Apr 2021 21:02:28 +0200 Subject: [PATCH] docs: add two gql examples --- graphql/examples/README.md | 5 ++++ graphql/examples/alola_road_encounters.gql | 2 +- graphql/examples/item_translations.gql | 27 ++++++++++++++++++++++ graphql/examples/pokemon_stats.gql | 23 ++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 graphql/examples/README.md create mode 100644 graphql/examples/item_translations.gql create mode 100644 graphql/examples/pokemon_stats.gql diff --git a/graphql/examples/README.md b/graphql/examples/README.md new file mode 100644 index 00000000..59ca62cd --- /dev/null +++ b/graphql/examples/README.md @@ -0,0 +1,5 @@ +# GraphQL examples + +You can use all the `.gql` examples in our console at https://beta.pokeapi.co/graphql/console/. + +Inside the folders you find GraphQL queries implemented in different languages, frameworks and libraries. diff --git a/graphql/examples/alola_road_encounters.gql b/graphql/examples/alola_road_encounters.gql index 625197c5..b3dcafb9 100644 --- a/graphql/examples/alola_road_encounters.gql +++ b/graphql/examples/alola_road_encounters.gql @@ -3,7 +3,7 @@ Finds Pokemons in Alola that evolve when you are in a particular location. Variables: { - "region": "alola" + "region": "alola" } """ diff --git a/graphql/examples/item_translations.gql b/graphql/examples/item_translations.gql new file mode 100644 index 00000000..e0008aa6 --- /dev/null +++ b/graphql/examples/item_translations.gql @@ -0,0 +1,27 @@ +# for each language, list all items and the relative English translation +query getItemsTranslation1 { + pokemon_v2_language { + name + iso639 + iso3166 + items: pokemon_v2_itemnames { + name + englishName: pokemon_v2_item { + name + } + } + } +} + +# for each item, show the English name and get all it's translations +query getItemsTranslation2 { + items: pokemon_v2_item { + name + translations: pokemon_v2_itemnames { + foreignName: name + language: pokemon_v2_language { + name + } + } + } +} \ No newline at end of file diff --git a/graphql/examples/pokemon_stats.gql b/graphql/examples/pokemon_stats.gql new file mode 100644 index 00000000..01990293 --- /dev/null +++ b/graphql/examples/pokemon_stats.gql @@ -0,0 +1,23 @@ +query tallest { + pokemon: pokemon_v2_pokemon(order_by: {height: desc}, limit: 3, where: {is_default: {_eq: true}}) { + name + height + } +} + +query fattest { + pokemon: pokemon_v2_pokemon(order_by: {weight: desc}, limit: 3, where: {is_default: {_eq: true}}) { + name + weight + } +} + +query avgHappiness { + species: pokemon_v2_pokemonspecies_aggregate { + aggregate { + avg { + base_happiness + } + } + } +}