-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
40 lines (34 loc) · 930 Bytes
/
app.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
import express from 'express'
import { appConfig, Logger } from './config'
import config from './config/env'
import { ApolloServer } from 'apollo-server-express'
import { resolvers, typeDefs } from './app/graphql'
import { PostService } from './app/services'
import db from './app/db'
global.logger = Logger.createLogger({ label: 'GRAPHQL_ADO' })
const { postsDataLoader } = PostService
const server = new ApolloServer({
typeDefs,
resolvers,
context: ({ req }) => ({
req,
loaders: {
notesLoader: postsDataLoader()
}
})
})
const app = express()
appConfig(app, server)
const port = config.PORT || 3000
// server listens for connections
db.connect()
.then(() => {
app.listen({ port }, () => {
logger.info(`🚀🚀 Server ready at http://localhost:${port}${server.graphqlPath}`)
})
})
.catch((error) => {
logger.error(error.message)
process.exit(1)
})
export default app