-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (27 loc) · 815 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
// dependency imports
const { ApolloServer, PubSub } = require('apollo-server');
const mongoose = require('mongoose');
// relitave imports
const typeDefs = require('./graphql/typeDefs');
const resolvers = require('./graphql/resolvers');
const { MONGODB } = require('./config'); // password and connection URL
const pubsub = new PubSub();
const PORT = process.env.port || 5000;
const server = new ApolloServer({
typeDefs,
resolvers,
context: ({ req }) => ({ req, pubsub }),
});
// conects to server
mongoose
.connect(MONGODB, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => {
console.log('MongoDb Connected');
return server.listen({ port: PORT });
})
.then((res) => {
console.log(`Server running at ${res.url}`);
})
.catch((err) => {
console.error(err);
});