-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (28 loc) · 895 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
const express = require('express')
const { ApolloServer, gql } = require('apollo-server-express')
const { fileLoader, mergeTypes, mergeResolvers } = require('merge-graphql-schemas')
const path = require('path')
const cors = require('cors')
const db = require('./models')
const { middleware } = require('./helpers/auth')
const typeDefs = mergeTypes(fileLoader(path.join(__dirname, './types')))
const resolvers = mergeResolvers(fileLoader(path.join(__dirname, './resolvers')))
const server = new ApolloServer({
typeDefs: gql(typeDefs),
resolvers,
context: ({req}) => {
return {
db,
user: req.user
}
}
})
const app = express()
app.use(cors(), middleware)
server.applyMiddleware({ app })
const PORT = process.env.PORT
db.sequelize.sync({}).then(() => {
app.listen(PORT, () =>
console.log(`Server ready at http://localhost:${PORT}${server.graphqlPath}`)
)
})