-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
47 lines (38 loc) · 948 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
38
39
40
41
42
43
44
45
46
47
'use strict'
const Hapi = require('@hapi/hapi')
const { ApolloServer } = require('apollo-server-hapi')
const typeDefs = require('./schema')
const AsteroidAPI = require('./asteroid')
const resolvers = require('./resolvers')
const plugin = require('@newrelic/apollo-server-plugin')
const HOST = 'localhost'
const PORT = 6000
async function StartServer() {
const server = new ApolloServer({
typeDefs,
resolvers,
dataSources: () => ({
asteroidAPI: new AsteroidAPI(),
}),
context: () => {
return {
token: process.env.NASA_API_KEY
}
},
plugins: [
plugin
]
})
const app = new Hapi.server({
host: HOST,
port: PORT
})
await server.applyMiddleware({
app: app,
path: '/gql'
})
await server.installSubscriptionHandlers(app.listener)
await app.start()
console.log(`Server running at: ${app.info.uri}`)
}
StartServer().catch(error => console.log(error))