-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (33 loc) · 1.01 KB
/
index.js
File metadata and controls
39 lines (33 loc) · 1.01 KB
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
const { ApolloServer } = require("apollo-server-express");
const schema = require("./src/schema");
const resolvers = require("./src/resolvers");
const authJwt = require("./config/authJwt");
const express = require("express");
const db = require("./models");
const cors = require("cors");
const http = require("http");
require("dotenv").config();
const port = process.env.PORT || 4000;
db.sequelize.sync({ force: true }).then(async () => {
console.log("Drop and re-sync db.");
});
const app = express();
app.use(cors());
const server = new ApolloServer({
introspection: true,
typeDefs: schema,
resolvers,
context: async ({ req }) => {
//using this for authentication
const authUser = await authJwt.getUser(req);
return {
authUser,
};
},
});
server.applyMiddleware({ app, path: "/graphql" });
const httpServer = http.createServer(app);
server.installSubscriptionHandlers(httpServer);
httpServer.listen({ port: port }, () => {
console.log(`Server ready at http://localhost:${port}/graphql`);
});