Skip to content

v1beta2 #1264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 20, 2025
Merged

v1beta2 #1264

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
28 changes: 26 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ veekun_pokedex_repository = ../pokedex
local_config = --settings=config.local
docker_config = --settings=config.docker-compose
gql_compose_config = -f docker-compose.yml -f Resources/compose/docker-compose-prod-graphql.yml
gqlv1beta_compose_config = -f docker-compose.yml -f Resources/compose/docker-compose-prod-graphql.yml -f Resources/compose/docker-compose-prod-graphql-v1beta.yml

.PHONY: help
.SILENT:
Expand Down Expand Up @@ -104,11 +105,17 @@ sync-to-veekun: pull pull-veekun # Copy data from this repository to ../pokedex
# read-env-file: # Exports ./.env into shell environment variables
# export `egrep -v '^#' .env | xargs`

hasura-export-v1beta:
hasura md export --project graphql/v1beta

hasura-apply-v1beta:
hasura md apply --project graphql/v1beta

hasura-export: # Export Hasura configuration, be sure to have set HASURA_GRAPHQL_ADMIN_SECRET
hasura md export --project graphql
hasura md export --project graphql/v1beta2

hasura-apply: # Apply local Hasura configuration, be sure to have set HASURA_GRAPHQL_ADMIN_SECRET
hasura md apply --project graphql
hasura md apply --project graphql/v1beta2

hasura-get-anon-schema: # Dumps GraphQL schema
gq http://localhost:8080/v1/graphql --introspect > graphql/schema.graphql
Expand Down Expand Up @@ -143,6 +150,23 @@ down-graphql-prod:
docker volume prune --all --force
sync; echo 3 > /proc/sys/vm/drop_caches

update-graphql-v1beta-data-prod:
docker compose ${gqlv1beta_compose_config} stop
git pull origin master
git submodule update --remote --merge
docker compose ${gqlv1beta_compose_config} up --pull always -d app cache db
sync; echo 3 > /proc/sys/vm/drop_caches
make docker-migrate
make docker-build-db
docker compose ${gqlv1beta_compose_config} stop app cache
docker compose ${gqlv1beta_compose_config} up --pull always -d graphql-engine graphiql
sleep 120
make hasura-apply-v1beta
docker compose ${gqlv1beta_compose_config} up --pull always -d web
docker compose exec -T web sh -c 'rm -rf /tmp/cache/*'
docker image prune -af
sync; echo 3 > /proc/sys/vm/drop_caches

# Nginx doesn't start if upstream graphql-engine is down
update-graphql-data-prod:
docker compose ${gql_compose_config} stop
Expand Down
4 changes: 4 additions & 0 deletions Resources/compose/docker-compose-prod-graphql-v1beta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: '2.4'
services:
graphiql:
image: pokeapi/graphiql:2.0.0
5 changes: 1 addition & 4 deletions Resources/compose/docker-compose-prod-graphql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@ services:
HASURA_GRAPHQL_EVENTS_HTTP_POOL_SIZE: 10

graphiql:
image: pokeapi/graphiql:2.0.0
image: pokeapi/graphiql:2.0.1
expose:
- 80
depends_on:
- graphql-engine
restart: always

volumes:
graphiql:
2 changes: 1 addition & 1 deletion Resources/k8s/kustomize/base/jobs/load-graphql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ spec:
git clone https://github.com/PokeAPI/pokeapi.git &&
cd pokeapi &&
(git checkout $(POKEAPI_CHECKOUT_REF) || git checkout master) &&
hasura md apply --endpoint http://graphql:8080 --project graphql --admin-secret $(HASURA_GRAPHQL_ADMIN_SECRET)
hasura md apply --endpoint http://graphql:8080 --project graphql/v1beta2 --admin-secret $(HASURA_GRAPHQL_ADMIN_SECRET)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions graphql/v1beta2/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 3
endpoint: http://localhost:8080
metadata_directory: metadata
actions:
kind: synchronous
handler_webhook_baseurl: http://localhost:3000
5 changes: 5 additions & 0 deletions graphql/v1beta2/examples/README.md
Original file line number Diff line number Diff line change
@@ -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.
26 changes: 26 additions & 0 deletions graphql/v1beta2/examples/alola_road_encounters.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
Finds Pokemons in Alola that evolve when you are in a particular location.

Variables:
{
"region": "alola"
}
"""

query location_evolutions_in_alola($region: String) {
region: region(where: {name: {_eq: $region}}) {
name
location: locations_aggregate(where: {pokemonevolutions: {id: {_is_null: false}}}) {
nodes {
name
evolutions: pokemonevolutions_aggregate {
nodes {
species: pokemonspecy {
name
}
}
}
}
}
}
}
35 changes: 35 additions & 0 deletions graphql/v1beta2/examples/best_poison_grass_pokemon.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Returns the strongest 3 grass and poison pokemon. It uses thier stats to compute their strenght.
"""

query best_grass_poison_pokemons {
pokemon: pokemon(
where: {
_and: [
{
pokemontypes: {
type: { name: { _eq: "grass" } }
}
}
{
pokemontypes: {
type: { name: { _eq: "poison" } }
}
}
]
}
order_by: {
pokemonstats_aggregate: { sum: { base_stat: desc } }
}
limit: 3
) {
name
stats: pokemonstats_aggregate(order_by: {}) {
aggregate {
sum {
base_stat
}
}
}
}
}
17 changes: 17 additions & 0 deletions graphql/v1beta2/examples/gen3_species.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
query samplePokeAPIquery {
# Gets all the pokemon belonging to generation 3
gen3_species: pokemonspecies(where: {generation: {name: {_eq: "generation-iii"}}}, order_by: {id: asc}) {
name
id
}
# You can run multiple queries at the same time
# Counts how many pokemon where release for each generation
generations: generation {
name
pokemon_species: pokemonspecies_aggregate {
aggregate {
count
}
}
}
}
9 changes: 9 additions & 0 deletions graphql/v1beta2/examples/go/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Go examples

## `pokemon.go`

Fetches details about a Pokémon and prints an unformatted JSON to the `stdout`. The name of the Pokémon is passed as a variable.

```sh
go run pokemon.go # | jq
```
110 changes: 110 additions & 0 deletions graphql/v1beta2/examples/go/pokemon.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package main

import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)

type Operation struct {
Query string `json:"query"`
Variables map[string]interface{} `json:"variables"`
OperationName string `json:"operationName"`
}

var (
pokemonDetails = Operation{
OperationName: "pokemon_details",
Variables: map[string]interface{}{
"name": "staryu",
},
Query: `
query pokemon_details($name: String) {
species: pokemonspecies(where: {name: {_eq: $name}}) {
name
base_happiness
is_legendary
is_mythical
generation: generation {
name
}
habitat: pokemonhabitat {
name
}
pokemon: pokemons_aggregate(limit: 1) {
nodes {
height
name
id
weight
abilities: pokemonabilities_aggregate {
nodes {
ability: ability {
name
}
}
}
stats: pokemonstats {
base_stat
stat: stat {
name
}
}
types: pokemontypes {
slot
type: type {
name
}
}
levelUpMoves: pokemonmoves_aggregate(where: {movelearnmethod: {name: {_eq: "level-up"}}}, distinct_on: move_id) {
nodes {
move: move {
name
}
level
}
}
foundInAsManyPlaces: encounters_aggregate {
aggregate {
count
}
}
fireRedItems: pokemonitems(where: {version: {name: {_eq: "firered"}}}) {
item {
name
cost
}
rarity
}
}
}
flavorText: pokemonspeciesflavortexts(where: {language: {name: {_eq: "en"}}, version: {name: {_eq: "firered"}}}) {
flavor_text
}
}
}
`,
}
)

func main() {
url := "https://beta.pokeapi.co/graphql/v1beta"
body, err := json.Marshal(pokemonDetails)
if err != nil {
log.Fatal(err)
}

resp, err := http.Post(url, "", bytes.NewReader(body))
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
body, err = ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(body))
}
27 changes: 27 additions & 0 deletions graphql/v1beta2/examples/item_translations.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# for each language, list all items and the relative English translation
query getItemsTranslation1 {
language {
name
iso639
iso3166
items: itemnames {
name
englishName: item {
name
}
}
}
}

# for each item, show the English name and get all its translations
query getItemsTranslation2 {
items: item {
name
translations: itemnames {
foreignName: name
language: language {
name
}
}
}
}
10 changes: 10 additions & 0 deletions graphql/v1beta2/examples/node/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Node examples

## `pokemon.js`

Fetches info about Staryu using `node-fetch`.

```sh
npm i
node pokemon.js
```
13 changes: 13 additions & 0 deletions graphql/v1beta2/examples/node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions graphql/v1beta2/examples/node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "examples",
"version": "1.0.0",
"description": "",
"main": "''",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"node-fetch": "^2.6.1"
}
}
Loading