Skip to content

Instantly share code, notes, and snippets.

@cdaz5
Created April 12, 2018 11:09
Show Gist options
  • Select an option

  • Save cdaz5/1f467ff712acbab0f7b8f6da17eded57 to your computer and use it in GitHub Desktop.

Select an option

Save cdaz5/1f467ff712acbab0f7b8f6da17eded57 to your computer and use it in GitHub Desktop.
const { GraphQLServer } = require("graphql-yoga");
const fetch = require("node-fetch");
const typeDefs = `
type Query {
getPokemon(id: Int!): Pokemon
}
type Pokemon {
id: Int
name: String
height: Int
abilities: [AbilityObj]
stats: [StatObj]
}
type AbilityObj {
slot: Int
is_hidden: Boolean
ability: Ability
}
type Ability {
name: String
url: String
}
type StatObj {
effort: Int
base_stat: Int
stat: Stat
}
type Stat {
name: String
url: String
}
`;
const resolvers = {
Query: {
getPokemon: async (_, { id }) => {
const response = await fetch(`http://pokeapi.co/api/v2/pokemon/${id}`);
return response.json();
}
}
};
const server = new GraphQLServer({ typeDefs, resolvers });
server.start(() => console.log("Server is running on localhost:4000"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment