-
Notifications
You must be signed in to change notification settings - Fork 68
/
apollo.ts
66 lines (61 loc) · 1.83 KB
/
apollo.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import {
ApolloServer,
makeExecutableSchema,
ApolloServerExpressConfig,
} from "apollo-server-express";
import vanity from "./vanity";
import http from "http";
import ipAddress from "../helpers/ipaddress";
import {typeDefs, resolvers} from "../data";
import chalk from "chalk";
// Load some other stuff
import "../events";
import "../processes";
export const schema = makeExecutableSchema({
typeDefs,
resolvers,
resolverValidationOptions: {
requireResolversForResolveType: false,
},
});
// TODO: Change app to the express type
export default (app: any, SERVER_PORT: number) => {
const graphqlOptions: ApolloServerExpressConfig = {
schema,
engine: {
apiKey: "service:Thorium:yZHa-qq7-_kVSpmsc9Ka1A",
},
tracing: process.env.NODE_ENV !== "production",
introspection: true,
playground: true,
uploads: false,
context: ({req, connection}) => ({
clientId: req?.headers.clientid || connection?.context.clientId,
core: req?.headers.core,
}),
};
const apollo = new ApolloServer(graphqlOptions);
apollo.applyMiddleware({app});
const httpServer = http.createServer(app);
apollo.installSubscriptionHandlers(httpServer);
vanity();
app.on("error", (err: {code: string}) => {
if (err.code === "EADDRINUSE") {
console.log(
chalk.redBright(
"There is already a version of Thorium running on this computer. Shutting down...",
),
);
process.exit(0);
}
});
httpServer.listen(SERVER_PORT, () => {
console.log(
`
Client Server is now running on http://${ipAddress}:${SERVER_PORT}/client
Access the Flight Director on http://${ipAddress}:${SERVER_PORT}
GraphQL Server is now running on http://${ipAddress}:${SERVER_PORT}/graphql
🚀 Subscriptions ready at ws://${ipAddress}:${SERVER_PORT}${apollo.subscriptionsPath}`,
);
});
};