-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
29 lines (24 loc) · 893 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
const server = require("express")
const bodyParser = require("body-parser")
const dbConnection = require('./Database/mongoose')
const axios = require("axios")
const { ApolloServer } = require('@apollo/server');
const { expressMiddleware } = require("@apollo/server/express4")
const cors = require("cors")
const PORT = process.env.PORT || 3000
dbConnection.mongooseDb()
const app = server()
const typeDefs = require('./graphql/schema');
const resolvers = require('./graphql/resolvers');
const apolloServer = new ApolloServer({ typeDefs, resolvers });
const startServer = async () => {
app.use(cors())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
await apolloServer.start();
app.use('/graphql', cors(), expressMiddleware(apolloServer))
app.listen(PORT, () => {
console.log(`Magic happening on ${PORT}`)
})
}
startServer()