📎 Webclip
Turn a REST API into a GraphQL API
The post explains how to turn a single REST endpoint into a GraphQL endpoint. It uses the PokeAPI Pikachu endpoint as the starting point, then defines a Pokemon type, a getPokemon query, and a resolver that fetches data from /pokemon/<id>/.
Reading notes#
- The example starts from a simple GET REST endpoint for Pikachu.
- The GraphQL schema defines a
Pokemontype withid,name, andbase_experience. - The query type adds
getPokemon(id: String!): Pokemon. - The resolver handles
getPokemonby sending a GET request toMY_REST_URL + '/pokemon/' + id + '/'. - The article shows the query in GraphQL Playground and returns real data from PokeAPI.
- It suggests adding another field to the schema and query as a practice exercise.
