-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
56 lines (43 loc) · 1.24 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
52
53
54
55
56
const express = require('express')
const { ApolloServer } = require("apollo-server-express");
const { execute, subscribe } = require("graphql");
const { SubscriptionServer } = require('subscriptions-transport-ws');
const {json} = require("body-parser");
const { createServer } = require('http');
const typeDef = require('./graphql/schema');
const resolvers = require('./graphql/resolvers');
const model = require('./models');
const cors = require('cors')
const isProduction = process.env.NODE_ENV === 'production';
require('dotenv').config();
const app = express();
app.use(cors());
// app.use(express.json());
app.use("/graphql", json())
// if (!isProduction) {
// app.use(errorhandler());
// }
const apolloServer = new ApolloServer({
typeDefs: typeDef,
resolvers: resolvers,
context: {model},
// subscriptions
})
apolloServer.applyMiddleware({app})
const server = createServer(app);
app.get('/', (req, res) => {
res.status(200).send('Hello World!');
});
const APP_PORT = process.env.PORT || 3000;
server.listen(APP_PORT, () => {
new SubscriptionServer({
execute,
subscribe,
schema: typeDef,
}, {
server,
path: '/subscriptions',
});
process.stdout.write(`listening on port ${APP_PORT}\n`);
});
module.exports = app;