-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
51 lines (37 loc) · 1.04 KB
/
server.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
48
49
50
51
const express = require('express');
const { ApolloServer, gql } = require('apollo-server-express');
const cors = require('cors');
const dotEnv = require('dotenv');
const resolvers = require('./resolvers');
const typeDefs = require('./typeDefs');
const {tasks, users} = require('./constants/index');
const { connection } = require('./database/util');
const { verifyUser } = require('./helper/context');
// set env variables
dotEnv.config();
const app = express();
// db connectivity
connection();
//cors
app.use(cors());
// body parser middleware
app.use(express.json());
const apolloServer = new ApolloServer({
typeDefs,
resolvers,
context: ({req}) => {
verifyUser(req)
return{
email:"test@gmail.com"
}
}
});
apolloServer.applyMiddleware({ app, path: '/graphql' });
const PORT = process.env.PORT || 3000;
app.use('/', (req, res, next) => {
res.send({ message: 'Hello' });
})
app.listen(PORT, () => {
console.log(`Server listening on PORT: ${PORT}`);
console.log(`Graphql Endpoint: ${apolloServer.graphqlPath}`);
});