Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

GraphQL API how to filter Pokemon by game? #152

Open
martipello opened this issue Mar 14, 2023 · 5 comments
Open

GraphQL API how to filter Pokemon by game? #152

martipello opened this issue Mar 14, 2023 · 5 comments

Comments

@martipello
Copy link

Hey I'm using the GraphQL API and I'm trying to filter Pokemon by game but it doesn't seem to be possible any ideas or suggestions?
so far i've tried a where clause on the version id in encounters and in game indices but with no success
an example of what i want is if i get pokemon from 0 - 30 with version name red i'd expect to see ekans and arbok but not sandshrew or sandslash

game indices example
pokemon_v2_pokemon(where: {pokemon_v2_pokemontypes: {type_id: {_in: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 19]}, pokemon_v2_pokemon: {name: {_like: "%%"}}}, pokemon_v2_pokemongameindices: {pokemon_v2_version: {}, version_id: {_in: [1]}}}, order_by: {id: asc}, offset: 0, limit: 30)

species/generation/versions example
pokemon_v2_pokemon(where: {pokemon_v2_pokemontypes: {type_id: {_in: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 19]}, pokemon_v2_pokemon: {name: {_like: "%%"}}}, pokemon_v2_pokemonspecy: {pokemon_v2_generation: {pokemon_v2_versiongroups: {pokemon_v2_versions: {id: {_in: [1]}}}}}}, order_by: {id: asc, pokemon_v2_pokemonspecy: {}}, offset: 0, limit: 30)

@Naramsim
Copy link
Member

Hi, I came up with this query:

query MyQuery {
  pokemon_v2_pokemonspecies(
    where: {
      pokemon_v2_generation: {
        pokemon_v2_versiongroups: {
          pokemon_v2_versions: { name: { _eq: "red" } }
        }
      }
    }
    order_by: { order: asc }
  ) {
    name
    id
  }
}

You can substitute red with a variable. Basically, you get every pokemon for a specific version (which can be seen as a Nintendo game)

@Naramsim
Copy link
Member

Here all versions: https://pokeapi.co/api/v2/version/?offset=0&limit=2000

@martipello
Copy link
Author

martipello commented Mar 14, 2023

Sorry this doesn't work it will return sandshrew and sandslash which are exclusive to blue, really appreciate the help though

@Naramsim
Copy link
Member

then we lack this info

@martipello
Copy link
Author

i wonder how serebii.net are doing this https://www.serebii.net/rb/exclusives.shtml i see the exclusives in the url maybe a flag on the pokemon

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants