-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
36 lines (27 loc) · 907 Bytes
/
server.ts
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
import express from "express";
import { ApolloServer } from "apollo-server-express";
import { schema } from "./graphQL/modules";
import dotenv from "dotenv";
import { authMiddleware } from "./middleware/auth/auth";
import { users } from "@prisma/client";
import { ApolloServerPluginInlineTrace, PluginDefinition } from "apollo-server-core";
require('module-alias/register')
dotenv.config();
export default async function initApolloServer() {
const app = express();
app.use("/graphql", authMiddleware);
const server = new ApolloServer({
schema: schema,
context: ({ req, res }) => {
return {
res,
req,
logged_in_user: (req as any).user as users,
};
},
plugins: [...(process.env.NODE_ENV != "production" ? [ApolloServerPluginInlineTrace()]:[])],
});
await server.start();
server.applyMiddleware({ app });
return { server, app };
}