File tree Expand file tree Collapse file tree 4 files changed +41
-36
lines changed
Expand file tree Collapse file tree 4 files changed +41
-36
lines changed File renamed without changes.
Original file line number Diff line number Diff line change 1- const { ApolloServer, gql } = require ( 'apollo-server-cloudflare' )
1+ const { ApolloServer } = require ( 'apollo-server-cloudflare' )
22const { graphqlCloudflare } = require ( 'apollo-server-cloudflare/dist/cloudflareApollo' )
3- const { PokemonAPI } = require ( '../pokeapi' )
43
5- const typeDefs = gql `
6- type PokemonSprites {
7- front_default: String!
8- front_shiny: String!
9- front_female: String!
10- front_shiny_female: String!
11- back_default: String!
12- back_shiny: String!
13- back_female: String!
14- back_shiny_female: String!
15- }
4+ const PokemonAPI = require ( './datasources/pokeapi' )
5+ const resolvers = require ( '../resolvers' )
6+ const typeDefs = require ( '../schema' )
167
17- type Pokemon {
18- id: ID!
19- name: String!
20- height: Int!
21- weight: Int!
22- sprites: PokemonSprites!
23- }
24-
25- type Query {
26- pokemon(id: ID!): Pokemon
27- }
28- `
29-
30- const resolvers = {
31- Query : {
32- pokemon : async ( _source , { id } , { dataSources } ) => {
33- return dataSources . pokemonAPI . getPokemon ( id )
34- } ,
35- } ,
36- }
8+ const dataSources = ( ) => ( {
9+ pokemonAPI : new PokemonAPI ( ) ,
10+ } )
3711
3812const server = new ApolloServer ( {
3913 typeDefs,
4014 resolvers,
4115 introspection : true ,
42- dataSources : ( ) => ( {
43- pokemonAPI : new PokemonAPI ( ) ,
44- } ) ,
16+ dataSources,
4517} )
4618
4719const handler = ( request , _graphQLOptions ) =>
Original file line number Diff line number Diff line change 1+ module . exports = {
2+ Query : {
3+ pokemon : async ( _source , { id } , { dataSources } ) => {
4+ return dataSources . pokemonAPI . getPokemon ( id )
5+ } ,
6+ } ,
7+ }
Original file line number Diff line number Diff line change 1+ const { gql } = require ( 'apollo-server-cloudflare' )
2+
3+ module . exports = gql `
4+ type PokemonSprites {
5+ front_default: String!
6+ front_shiny: String!
7+ front_female: String!
8+ front_shiny_female: String!
9+ back_default: String!
10+ back_shiny: String!
11+ back_female: String!
12+ back_shiny_female: String!
13+ }
14+
15+ type Pokemon {
16+ id: ID!
17+ name: String!
18+ height: Int!
19+ weight: Int!
20+ sprites: PokemonSprites!
21+ }
22+
23+ type Query {
24+ pokemon(id: ID!): Pokemon
25+ }
26+ `
You can’t perform that action at this time.
0 commit comments