-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrs-index.ts
99 lines (91 loc) · 2.98 KB
/
rs-index.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// import http from 'http';
// import { EventEmitter } from 'events';
// import express, { RequestHandler, Express } from 'express';
// import { ApolloServer } from '@apollo/server';
// import { graphqlEventStream } from './schema-observer';
// import { execute } from 'graphql';
// import { makeExecutableSchema } from '@graphql-tools/schema';
// import { createWatcher } from './watcher';
// const compression = require('compression');
// const cors = require('cors');
// const getSchema = () => {
// // First clear require cache for the module
// delete require.cache[require.resolve('./schema/rs-schema')];
// const { typeDefs, resolvers } = require('./schema/rs-schema');
// return makeExecutableSchema({
// typeDefs,
// resolvers,
// })
// };
// const setupServer = async() => {
// const watcher = createWatcher();
// const emitter = new EventEmitter();
// const server = new ApolloServer({
// subscriptions: false,
// gateway: {
// load: async() => {
// const schema = getSchema();
// return {
// schema,
// executor: args => {
// return execute({
// ...args,
// schema,
// })
// }
// }
// },
// executor: execute,
// onSchemaChange: cb => {
// watcher.on('all', () => {
// console.log('updating schema..');
// const schema = getSchema();
// cb(schema);
// emitter.emit('schema:updated', schema);
// });
// return () => watcher.close();
// },
// },
// context({ req }) {
// // throw new ApolloError('NOT_FOUND', '404');
// return { req };
// },
// formatError(error) {
// if (!process.env.NODE_ENV || process.env.NODE_ENV === 'development') {
// // logging the errors can help in development
// // tslint:disable-next-line
// console.log(error);
// }
// return error;
// }
// });
// const app = express();
// // Compression doesn't work well with server side events
// // app.use(compression());
// app.use(cors());
// app.use((req, res, next) => {
// // console.log(req.headers);
// return next();
// });
// graphqlEventStream({
// app,
// emitter,
// streamPath: '/stream',
// });
// server.applyMiddleware({ app, path: '/graphql' });
// const httpServer = http.createServer(app);
// // subscriptions are not supported in apollo gateway
// // server.installSubscriptionHandlers(httpServer);
// app.all('/test', (req, res) => {
// // console.log(req.headers);
// res.send('');
// });
// const PORT = process.env.__PORT__ || 5400;
// httpServer.listen(PORT, () => {
// // tslint:disable-next-line
// console.log(`Server running at http://localhost:${PORT}${server.graphqlPath}`);
// // tslint:disable-next-line
// // console.log(`Subscription running at ws://localhost:${PORT}${server.subscriptionsPath}`);
// });
// };
// setupServer();