This is a learning project. It's not intended for production use and it may be slow.
- Split all resolvers into separate files
- Support all API endpoints and types
- Check all missing properties in types
- Change all lists to connections for pagination.
- Do not make additional API requests when requesting only
name
of NamedAPIResource - If possible, add an optional parameter for
Name
,FlavorText
to specify language - Ability to search resources by
name
and not justid
ifid
isInt
(already possible in PokeAPI) (maybe justunion IdOrName = Int | String
)
git clone https://github.com/vitalyavolyn/pokeapi-graphql.git
cd pokeapi-graphql
yarn
If you don't want to bother PokeAPI maintainers and not to hit rate limits you should launch PokeAPI locally.
You also want you own PokeAPI because this wrapper often requests a ton of data, which is disallowed by pokeapi.co.
Here you have two options: launching a PokeAPI python server with Docker or using static data from PokeAPI/api-data. Static data is faster, but it doesn't support names in queries (for example, you can't query Fire type using type(id: "fire")
, use type(id: "10")
instead.)
Instructions on how to do this can be found in the PokeAPI repository
Clone PokeAPI/api-data and serve data
directory using HTTP server of your choice.
git clone https://github.com/PokeAPI/api-data.git
cd api-data/data
npx serve
You need to provide POKEAPI_STATIC
environment variable to request /index.json
for every request, since this is how data is structured.
# If you have your instance of PokeAPI running
export POKEAPI=http://localhost:PORT
# If you use static file server
export POKEAPI_STATIC=1
yarn start
Success! Now you should be able to see GraphQL Playground at http://localhost:3000/graphql
Try these example queries:
# Get all fire type pokemon names
query {
type(id: "fire") {
pokemon {
pokemon {
name
}
}
}
}
# Find all damage relations of Fire type
query {
type(id: "fire") {
damageRelations {
noDamageTo { name }
halfDamageTo { name }
doubleDamageTo { name }
noDamageFrom { name }
halfDamageFrom { name }
doubleDamageFrom { name }
}
}
}