Created
April 12, 2018 11:09
-
-
Save cdaz5/1f467ff712acbab0f7b8f6da17eded57 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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