Skip to content

Commit

Permalink
Begin re-organizing files to follow Apollo tuts
Browse files Browse the repository at this point in the history
  • Loading branch information
kristianfreeman committed Aug 19, 2019
1 parent 2e48eee commit 943dd33
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 36 deletions.
File renamed without changes.
44 changes: 8 additions & 36 deletions src/handlers/apollo.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,19 @@
const { ApolloServer, gql } = require('apollo-server-cloudflare')
const { ApolloServer } = require('apollo-server-cloudflare')
const { graphqlCloudflare } = require('apollo-server-cloudflare/dist/cloudflareApollo')
const { PokemonAPI } = require('../pokeapi')

const typeDefs = gql`
type PokemonSprites {
front_default: String!
front_shiny: String!
front_female: String!
front_shiny_female: String!
back_default: String!
back_shiny: String!
back_female: String!
back_shiny_female: String!
}
const PokemonAPI = require('./datasources/pokeapi')
const resolvers = require('../resolvers')
const typeDefs = require('../schema')

type Pokemon {
id: ID!
name: String!
height: Int!
weight: Int!
sprites: PokemonSprites!
}
type Query {
pokemon(id: ID!): Pokemon
}
`

const resolvers = {
Query: {
pokemon: async (_source, { id }, { dataSources }) => {
return dataSources.pokemonAPI.getPokemon(id)
},
},
}
const dataSources = () => ({
pokemonAPI: new PokemonAPI(),
})

const server = new ApolloServer({
typeDefs,
resolvers,
introspection: true,
dataSources: () => ({
pokemonAPI: new PokemonAPI(),
}),
dataSources,
})

const handler = (request, _graphQLOptions) =>
Expand Down
7 changes: 7 additions & 0 deletions src/resolvers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
Query: {
pokemon: async (_source, { id }, { dataSources }) => {
return dataSources.pokemonAPI.getPokemon(id)
},
},
}
26 changes: 26 additions & 0 deletions src/schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { gql } = require('apollo-server-cloudflare')

module.exports = gql`
type PokemonSprites {
front_default: String!
front_shiny: String!
front_female: String!
front_shiny_female: String!
back_default: String!
back_shiny: String!
back_female: String!
back_shiny_female: String!
}
type Pokemon {
id: ID!
name: String!
height: Int!
weight: Int!
sprites: PokemonSprites!
}
type Query {
pokemon(id: ID!): Pokemon
}
`

0 comments on commit 943dd33

Please sign in to comment.