-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (31 loc) · 1009 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
33
34
35
36
37
38
const { PrismaClient } = require('@prisma/client');
const express = require('express');
const { ApolloServer } = require('apollo-server-express');
const { PubSub } = require('graphql-subscriptions');
const cors = require('cors');
const bodyParser = require('body-parser');
const typeDefs = require('./graphql/typeDefs');
const resolvers = require('./graphql/resolvers/index');
const prisma = new PrismaClient();
const pubsub = new PubSub();
const apolloServer = new ApolloServer({
typeDefs,
resolvers,
context: ({ req }) => {
return {
prisma,
req,
pubsub
}
}
});
const app = express();
app.use('/graphql', bodyParser.json({ limit: '20mb' }));
app.use(cors());
apolloServer.applyMiddleware({ app });
// const server = createServer(app);
// apolloServer.installSubscriptionHandlers(server);
const PORT = process.env.PORT || 4000;
app.listen({ port: PORT }, () => {
console.log(`Server listening at http://localhost:${PORT}`)
});