pokedex icon indicating copy to clipboard operation
pokedex copied to clipboard

GraphQL API how to filter Pokemon by game?

Open martipello opened this issue 2 years ago • 5 comments

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)

martipello avatar Mar 14 '23 10:03 martipello

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 avatar Mar 14 '23 20:03 Naramsim

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

Naramsim avatar Mar 14 '23 20:03 Naramsim

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

martipello avatar Mar 14 '23 20:03 martipello

then we lack this info

Naramsim avatar Mar 14 '23 21:03 Naramsim

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

martipello avatar Mar 15 '23 07:03 martipello