-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (34 loc) · 906 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const { GraphQLServer } = require('graphql-yoga')
const fetch = require("node-fetch")
const typeDefs = `
type Query {
hello(name: String): String!
getCovid(country: String!):covid
}
type covid {
country: String
cases: Int
todayCases: Int,
deaths: Int,
todayDeaths: Int,
recovered: Int,
active: Int,
critical: Int,
casesPerOneMillion: Int,
deathsPerOneMillion: Int,
totalTests: Int,
testsPerOneMillion: Int
}
`
const baseURL = "https://coronavirus-19-api.herokuapp.com/countries/"
const resolvers = {
Query: {
hello: (_, { name }) => `Hello ${name || 'World'}`,
getCovid: async (_, {country}) => {
const response = await fetch(`${baseURL}${country}`);
return response.json()
},
},
}
const server = new GraphQLServer({ typeDefs, resolvers })
server.start(() => console.log('Server is running on localhost:4000'))