-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (24 loc) · 793 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
const { ApolloServer, PubSub } = require('apollo-server');
const mongoose = require('mongoose')
require('dotenv').config();
const typeDefs = require('./graphql/typeDefs')
const resolvers = require('./graphql/resolvers/index')
const PORT = process.env.PORT || 5000;
const pubsub = new PubSub();
const server = new ApolloServer({
typeDefs,
resolvers,
context: ({ req }) => ({ req, pubsub })
})
//Connect to mongodb
mongoose
.connect(process.env.MONGODB, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => {
return server.listen({ port: PORT })
.then(res => {
console.log(`✅ MongoDB Connected \n✅ GrapghQL server started on ${res.url} `)
})
})
.catch(err => {
console.error(err)
})