PokeAPI / pokedex

PokeAPI's fork for adding gen-8 data.
https://github.com/PokeAPI/pokedex/tree/master-pokeapi/pokeapi
MIT License
43 stars 40 forks source link

GraphQL API how to filter Pokemon by game? #152

Open martipello opened 1 year ago

martipello commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

martipello commented 1 year ago

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

Naramsim commented 1 year ago

then we lack this info

martipello commented 1 year ago

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