↓ Ir para o conteúdo principal

← todas as notas

📎 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 Pokemon type with id, name, and base_experience.
  • The query type adds getPokemon(id: String!): Pokemon.
  • The resolver handles getPokemon by sending a GET request to MY_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.