-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
31 lines (31 loc) · 896 Bytes
/
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
const { GraphQLServer, PubSub } = require('graphql-yoga')
const mongoose = require('mongoose');
const typeDefs = require("./src/typeDefs");
const resolvers = require("./src/resolvers");
const url = "<mongodb url>";
const connect = mongoose.connect(url, { useUnifiedTopology: true, useNewUrlParser: true, useFindAndModify: false});
connect.then((db) => {
console.log('Connected to the Database!');
}, (err) => {
console.log(err);
});
const pubsub = new PubSub();
const server = new GraphQLServer({
typeDefs,
resolvers,
context: {
pubsub
}
});
const options = {
port: 4000,
endpoint: '/graphql',
subscriptions: '/subscriptions',
playground: '/playground',
}
server.start(options, ({ port }) =>
console.log(
`Server started, listening on port ${port} for incoming requests.`,
),
)
//server.start(() => console.log('Server is running on localhost:4000'))