@common-stack/server-stack 7.0.4-alpha.15 → 7.0.4-alpha.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -7
- package/lib/MainStackServer.cjs +0 -231
- package/lib/MainStackServer.cjs.map +0 -1
- package/lib/MainStackServer.d.ts +0 -28
- package/lib/MainStackServer.mjs +0 -231
- package/lib/MainStackServer.mjs.map +0 -1
- package/lib/StackServer.cjs +0 -92
- package/lib/StackServer.cjs.map +0 -1
- package/lib/StackServer.d.ts +0 -20
- package/lib/StackServer.mjs +0 -92
- package/lib/StackServer.mjs.map +0 -1
- package/lib/api/remote-config.cjs +0 -6
- package/lib/api/remote-config.cjs.map +0 -1
- package/lib/api/remote-config.d.ts +0 -6
- package/lib/api/remote-config.mjs +0 -6
- package/lib/api/remote-config.mjs.map +0 -1
- package/lib/api/resolver.cjs +0 -12
- package/lib/api/resolver.cjs.map +0 -1
- package/lib/api/resolver.d.ts +0 -10
- package/lib/api/resolver.mjs +0 -12
- package/lib/api/resolver.mjs.map +0 -1
- package/lib/api/root-schema.graphqls.cjs +0 -2
- package/lib/api/root-schema.graphqls.cjs.map +0 -1
- package/lib/api/root-schema.graphqls.mjs +0 -2
- package/lib/api/root-schema.graphqls.mjs.map +0 -1
- package/lib/api/scalar.cjs +0 -16
- package/lib/api/scalar.cjs.map +0 -1
- package/lib/api/scalar.d.ts +0 -2
- package/lib/api/scalar.mjs +0 -16
- package/lib/api/scalar.mjs.map +0 -1
- package/lib/api/schema-builder.cjs +0 -160
- package/lib/api/schema-builder.cjs.map +0 -1
- package/lib/api/schema-builder.d.ts +0 -24
- package/lib/api/schema-builder.mjs +0 -160
- package/lib/api/schema-builder.mjs.map +0 -1
- package/lib/api/utils.cjs +0 -27
- package/lib/api/utils.cjs.map +0 -1
- package/lib/api/utils.d.ts +0 -4
- package/lib/api/utils.mjs +0 -27
- package/lib/api/utils.mjs.map +0 -1
- package/lib/config/env-config.cjs +0 -38
- package/lib/config/env-config.cjs.map +0 -1
- package/lib/config/env-config.d.ts +0 -21
- package/lib/config/env-config.mjs +0 -38
- package/lib/config/env-config.mjs.map +0 -1
- package/lib/config/index.d.ts +0 -1
- package/lib/config/moleculer.config.cjs +0 -191
- package/lib/config/moleculer.config.cjs.map +0 -1
- package/lib/config/moleculer.config.d.ts +0 -20
- package/lib/config/moleculer.config.mjs +0 -191
- package/lib/config/moleculer.config.mjs.map +0 -1
- package/lib/connectors/connection-broker.cjs +0 -61
- package/lib/connectors/connection-broker.cjs.map +0 -1
- package/lib/connectors/connection-broker.d.ts +0 -26
- package/lib/connectors/connection-broker.mjs +0 -61
- package/lib/connectors/connection-broker.mjs.map +0 -1
- package/lib/connectors/graphql-pubsub-connector.cjs +0 -28
- package/lib/connectors/graphql-pubsub-connector.cjs.map +0 -1
- package/lib/connectors/graphql-pubsub-connector.d.ts +0 -22
- package/lib/connectors/graphql-pubsub-connector.mjs +0 -28
- package/lib/connectors/graphql-pubsub-connector.mjs.map +0 -1
- package/lib/connectors/mongo-connector.cjs +0 -57
- package/lib/connectors/mongo-connector.cjs.map +0 -1
- package/lib/connectors/mongo-connector.d.ts +0 -21
- package/lib/connectors/mongo-connector.mjs +0 -57
- package/lib/connectors/mongo-connector.mjs.map +0 -1
- package/lib/connectors/nats-connector.cjs +0 -63
- package/lib/connectors/nats-connector.cjs.map +0 -1
- package/lib/connectors/nats-connector.d.ts +0 -20
- package/lib/connectors/nats-connector.mjs +0 -63
- package/lib/connectors/nats-connector.mjs.map +0 -1
- package/lib/connectors/redis-connector.cjs +0 -79
- package/lib/connectors/redis-connector.cjs.map +0 -1
- package/lib/connectors/redis-connector.d.ts +0 -30
- package/lib/connectors/redis-connector.mjs +0 -79
- package/lib/connectors/redis-connector.mjs.map +0 -1
- package/lib/graphql/directives/index.cjs +0 -10
- package/lib/graphql/directives/index.cjs.map +0 -1
- package/lib/graphql/directives/index.d.ts +0 -7
- package/lib/graphql/directives/index.mjs +0 -10
- package/lib/graphql/directives/index.mjs.map +0 -1
- package/lib/graphql/index.d.ts +0 -2
- package/lib/graphql/schema/directives.graphql.cjs +0 -1
- package/lib/graphql/schema/directives.graphql.cjs.map +0 -1
- package/lib/graphql/schema/directives.graphql.mjs +0 -1
- package/lib/graphql/schema/directives.graphql.mjs.map +0 -1
- package/lib/graphql/schema/index.cjs +0 -1
- package/lib/graphql/schema/index.cjs.map +0 -1
- package/lib/graphql/schema/index.d.ts +0 -1
- package/lib/graphql/schema/index.mjs +0 -1
- package/lib/graphql/schema/index.mjs.map +0 -1
- package/lib/index.cjs +0 -1
- package/lib/index.cjs.map +0 -1
- package/lib/index.d.ts +0 -3
- package/lib/index.mjs +0 -1
- package/lib/index.mjs.map +0 -1
- package/lib/interfaces/dbMigration.d.ts +0 -8
- package/lib/interfaces/graphql-request-context.d.ts +0 -15
- package/lib/interfaces/index.d.ts +0 -4
- package/lib/interfaces/module-interface.d.ts +0 -13
- package/lib/interfaces/moleculer.d.ts +0 -7
- package/lib/middleware/cors.cjs +0 -26
- package/lib/middleware/cors.cjs.map +0 -1
- package/lib/middleware/cors.d.ts +0 -6
- package/lib/middleware/cors.mjs +0 -26
- package/lib/middleware/cors.mjs.map +0 -1
- package/lib/middleware/error.cjs +0 -18
- package/lib/middleware/error.cjs.map +0 -1
- package/lib/middleware/error.d.ts +0 -9
- package/lib/middleware/error.mjs +0 -18
- package/lib/middleware/error.mjs.map +0 -1
- package/lib/middleware/moleculer-inter-namespace.cjs +0 -44
- package/lib/middleware/moleculer-inter-namespace.cjs.map +0 -1
- package/lib/middleware/moleculer-inter-namespace.d.ts +0 -2
- package/lib/middleware/moleculer-inter-namespace.mjs +0 -44
- package/lib/middleware/moleculer-inter-namespace.mjs.map +0 -1
- package/lib/middleware/sentry.cjs +0 -3
- package/lib/middleware/sentry.cjs.map +0 -1
- package/lib/middleware/sentry.d.ts +0 -2
- package/lib/middleware/sentry.mjs +0 -3
- package/lib/middleware/sentry.mjs.map +0 -1
- package/lib/middleware/services.cjs +0 -12
- package/lib/middleware/services.cjs.map +0 -1
- package/lib/middleware/services.d.ts +0 -2
- package/lib/middleware/services.mjs +0 -12
- package/lib/middleware/services.mjs.map +0 -1
- package/lib/plugins/index.d.ts +0 -2
- package/lib/plugins/invalidateCachePlugin.cjs +0 -59
- package/lib/plugins/invalidateCachePlugin.cjs.map +0 -1
- package/lib/plugins/invalidateCachePlugin.d.ts +0 -8
- package/lib/plugins/invalidateCachePlugin.mjs +0 -59
- package/lib/plugins/invalidateCachePlugin.mjs.map +0 -1
- package/lib/plugins/responseCachePlugin.cjs +0 -58
- package/lib/plugins/responseCachePlugin.cjs.map +0 -1
- package/lib/plugins/responseCachePlugin.d.ts +0 -8
- package/lib/plugins/responseCachePlugin.mjs +0 -58
- package/lib/plugins/responseCachePlugin.mjs.map +0 -1
- package/lib/servers/ExpressApp.cjs +0 -37
- package/lib/servers/ExpressApp.cjs.map +0 -1
- package/lib/servers/ExpressApp.d.ts +0 -3
- package/lib/servers/ExpressApp.mjs +0 -37
- package/lib/servers/ExpressApp.mjs.map +0 -1
- package/lib/servers/GraphqlServer.cjs +0 -142
- package/lib/servers/GraphqlServer.cjs.map +0 -1
- package/lib/servers/GraphqlServer.d.ts +0 -23
- package/lib/servers/GraphqlServer.mjs +0 -142
- package/lib/servers/GraphqlServer.mjs.map +0 -1
- package/lib/servers/GraphqlWs.cjs +0 -97
- package/lib/servers/GraphqlWs.cjs.map +0 -1
- package/lib/servers/GraphqlWs.d.ts +0 -14
- package/lib/servers/GraphqlWs.mjs +0 -97
- package/lib/servers/GraphqlWs.mjs.map +0 -1
- package/lib/servers/WebsocketMultipathUpdate.cjs +0 -63
- package/lib/servers/WebsocketMultipathUpdate.cjs.map +0 -1
- package/lib/servers/WebsocketMultipathUpdate.d.ts +0 -18
- package/lib/servers/WebsocketMultipathUpdate.mjs +0 -63
- package/lib/servers/WebsocketMultipathUpdate.mjs.map +0 -1
- package/lib/servers/mongodb-migration-update.d.ts +0 -12
- package/lib/servers/utils.d.ts +0 -14
- package/lib/utils/index.d.ts +0 -1
- package/lib/utils/migrations.cjs +0 -26
- package/lib/utils/migrations.cjs.map +0 -1
- package/lib/utils/migrations.d.ts +0 -8
- package/lib/utils/migrations.mjs +0 -26
- package/lib/utils/migrations.mjs.map +0 -1
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
'use strict';var server=require('@apollo/server'),express4=require('@apollo/server/express4'),cacheControl=require('@apollo/server/plugin/cacheControl'),drainHttpServer=require('@apollo/server/plugin/drainHttpServer');require('isomorphic-fetch');var express=require('express'),cors=require('cors'),Keyv=require('keyv'),KeyvRedis=require('@keyv/redis'),utils_keyvadapter=require('@apollo/utils.keyvadapter'),ws=require('ws'),invalidateCachePlugin=require('../plugins/invalidateCachePlugin.cjs'),responseCachePlugin=require('../plugins/responseCachePlugin.cjs'),GraphqlWs=require('./GraphqlWs.cjs'),envConfig=require('../config/env-config.cjs');if ((process.env.LOG_LEVEL && process.env.LOG_LEVEL === 'trace') || process.env.LOG_LEVEL === 'debug') ;
|
|
2
|
-
// @workaround as the `dataSources` not available in Subscription (websocket) Context.
|
|
3
|
-
// https://github.com/apollographql/apollo-server/issues/1526 need to revisit in Apollo-Server v3.
|
|
4
|
-
const constructDataSourcesForSubscriptions = (context, cache, dataSources) => {
|
|
5
|
-
const initializeDataSource = (instance) => {
|
|
6
|
-
instance.initialize({ context, cache });
|
|
7
|
-
};
|
|
8
|
-
for (const prop in dataSources) {
|
|
9
|
-
initializeDataSource(dataSources[prop]);
|
|
10
|
-
}
|
|
11
|
-
return dataSources;
|
|
12
|
-
};
|
|
13
|
-
class GraphqlServer {
|
|
14
|
-
app;
|
|
15
|
-
httpServer;
|
|
16
|
-
redisClient;
|
|
17
|
-
moduleService;
|
|
18
|
-
enableSubscription;
|
|
19
|
-
cacheKeyGenerator;
|
|
20
|
-
invalidateCacheKeyGenerator;
|
|
21
|
-
logger;
|
|
22
|
-
graphqlWsServer;
|
|
23
|
-
constructor(app, httpServer, redisClient, moduleService, enableSubscription = true, cacheKeyGenerator, invalidateCacheKeyGenerator) {
|
|
24
|
-
this.app = app;
|
|
25
|
-
this.httpServer = httpServer;
|
|
26
|
-
this.redisClient = redisClient;
|
|
27
|
-
this.moduleService = moduleService;
|
|
28
|
-
this.enableSubscription = enableSubscription;
|
|
29
|
-
this.cacheKeyGenerator = cacheKeyGenerator;
|
|
30
|
-
this.invalidateCacheKeyGenerator = invalidateCacheKeyGenerator;
|
|
31
|
-
this.logger = this.moduleService.logger.child({ className: 'GraphqlServer' });
|
|
32
|
-
if (enableSubscription) {
|
|
33
|
-
const wsServer = new ws.WebSocketServer({
|
|
34
|
-
server: this.httpServer,
|
|
35
|
-
path: envConfig.config.GRAPHQL_ENDPOINT,
|
|
36
|
-
});
|
|
37
|
-
this.graphqlWsServer = new GraphqlWs.GraphqlWs(wsServer, this.moduleService, this.redisClient);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
async initialize() {
|
|
41
|
-
this.logger.info('GraphqlServer initializing...');
|
|
42
|
-
this.graphqlWsServer.create();
|
|
43
|
-
const apolloServer = this.configureApolloServer();
|
|
44
|
-
await apolloServer.start();
|
|
45
|
-
const corsOptions = {
|
|
46
|
-
origin: [envConfig.config.CLIENT_URL],
|
|
47
|
-
credentials: true,
|
|
48
|
-
};
|
|
49
|
-
this.app.use(__GRAPHQL_ENDPOINT__, cors(corsOptions), express.json(), express4.expressMiddleware(apolloServer, {
|
|
50
|
-
context: async ({ req, res, connection }) => {
|
|
51
|
-
let context;
|
|
52
|
-
let addons = {};
|
|
53
|
-
const dataSources = this.moduleService.dataSource;
|
|
54
|
-
try {
|
|
55
|
-
if (connection) {
|
|
56
|
-
context = connection.context;
|
|
57
|
-
if (!context.dataSources) {
|
|
58
|
-
addons = {
|
|
59
|
-
dataSources: constructDataSourcesForSubscriptions(connection.context, this.redisClient, dataSources),
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
addons = {
|
|
64
|
-
dataSources,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
const pureContext = await this.moduleService.createContext(req, res);
|
|
70
|
-
const contextServices = await this.moduleService.serviceContext(req, res);
|
|
71
|
-
context = {
|
|
72
|
-
...pureContext,
|
|
73
|
-
...contextServices,
|
|
74
|
-
preferences: this.moduleService.defaultPreferences,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
context.userIp = this.getUserIpAddress(req);
|
|
78
|
-
}
|
|
79
|
-
catch (err) {
|
|
80
|
-
this.logger.error(err, 'adding context to graphql failed due to [%s]', err.message);
|
|
81
|
-
throw err;
|
|
82
|
-
}
|
|
83
|
-
return {
|
|
84
|
-
req,
|
|
85
|
-
res,
|
|
86
|
-
dataSources,
|
|
87
|
-
...context,
|
|
88
|
-
...addons,
|
|
89
|
-
};
|
|
90
|
-
},
|
|
91
|
-
}));
|
|
92
|
-
this.logger.info('GraphqlServer initialized - ', envConfig.config.CLIENT_URL);
|
|
93
|
-
}
|
|
94
|
-
getUserIpAddress(req) {
|
|
95
|
-
let ip = (req?.headers['x-forwarded-for'] || '').split(',')[0] || req?.connection?.remoteAddress;
|
|
96
|
-
if (ip.substr(0, 7) === '::ffff:') {
|
|
97
|
-
ip = ip.substr(7);
|
|
98
|
-
}
|
|
99
|
-
if (ip === '::1') {
|
|
100
|
-
ip = '127.0.0.1';
|
|
101
|
-
}
|
|
102
|
-
return ip;
|
|
103
|
-
}
|
|
104
|
-
configureApolloServer() {
|
|
105
|
-
const redisStore = new KeyvRedis(this.redisClient);
|
|
106
|
-
redisStore.on('error', (err) => {
|
|
107
|
-
this.logger.error(err, 'Redis connection error:');
|
|
108
|
-
});
|
|
109
|
-
const keyvCache = new Keyv({ store: redisStore, namespace: envConfig.config.APP_NAME });
|
|
110
|
-
const cacheAdapter = new utils_keyvadapter.KeyvAdapter(keyvCache);
|
|
111
|
-
const cacheGet = cacheAdapter.get.bind(cacheAdapter);
|
|
112
|
-
cacheAdapter.get = (key) => cacheGet(key.replaceAll('fqc:', ''));
|
|
113
|
-
const cacheSet = cacheAdapter.set.bind(cacheAdapter);
|
|
114
|
-
cacheAdapter.set = (key, value, opts) => cacheSet(key.replaceAll('fqc:', ''), value, opts);
|
|
115
|
-
const { cacheKeyGenerator, invalidateCacheKeyGenerator, logger } = this;
|
|
116
|
-
const serverConfig = {
|
|
117
|
-
schema: this.moduleService.schema,
|
|
118
|
-
allowBatchedHttpRequests: true,
|
|
119
|
-
cache: cacheAdapter,
|
|
120
|
-
plugins: [
|
|
121
|
-
drainHttpServer.ApolloServerPluginDrainHttpServer({ httpServer: this.httpServer }),
|
|
122
|
-
cacheControl.ApolloServerPluginCacheControl(),
|
|
123
|
-
invalidateCachePlugin.invalidateCachePlugin({ cache: this.redisClient, invalidateCacheKeyGenerator }),
|
|
124
|
-
responseCachePlugin.responseCachePlugin({ logger, cacheKeyGenerator }),
|
|
125
|
-
],
|
|
126
|
-
};
|
|
127
|
-
if (this.enableSubscription) {
|
|
128
|
-
serverConfig.plugins.push({
|
|
129
|
-
async serverWillStart() {
|
|
130
|
-
const response = {
|
|
131
|
-
async drainServer() {
|
|
132
|
-
await this?.graphqlWsServer?.disconnect();
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
response.drainServer.bind(this);
|
|
136
|
-
return response;
|
|
137
|
-
},
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
return new server.ApolloServer(serverConfig);
|
|
141
|
-
}
|
|
142
|
-
}exports.GraphqlServer=GraphqlServer;//# sourceMappingURL=GraphqlServer.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GraphqlServer.cjs","sources":["../../src/servers/GraphqlServer.ts"],"sourcesContent":[null],"names":["WebSocketServer","config","GraphqlWs","expressMiddleware","KeyvAdapter","ApolloServerPluginDrainHttpServer","ApolloServerPluginCacheControl","invalidateCachePlugin","responseCachePlugin","ApolloServer"],"mappings":"moBAsB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AC,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QAEnG,MAAM,EAAE,iBAAiB,EAAE,2BAA2B,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;AACxE,QAAA,MAAM,YAAY,GAAqC;AACnD,YAAA,MAAM,EAAE,IAAI,CAAC,aAAa,CAAC,MAAM;AACjC,YAAA,wBAAwB,EAAE,IAAI;AAC9B,YAAA,KAAK,EAAE,YAAY;AACnB,YAAA,OAAO,EAAE;gBACLC,iDAAiC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC;AAClE,gBAAAC,2CAA8B,EAAE;gBAChCC,2CAAqB,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,2BAA2B,EAAE,CAAC;AAC/E,gBAAAC,uCAAmB,CAAC,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC;AACrD,aAAA;SACJ,CAAC;AAEF,QAAA,IAAI,IAAI,CAAC,kBAAkB,EAAE;AACzB,YAAA,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC;AACtB,gBAAA,MAAM,eAAe,GAAA;AACjB,oBAAA,MAAM,QAAQ,GAAG;AACb,wBAAA,MAAM,WAAW,GAAA;AACb,4BAAA,MAAM,IAAI,EAAE,eAAe,EAAE,UAAU,EAAE,CAAC;yBAC7C;qBACJ,CAAC;AACF,oBAAA,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAChC,oBAAA,OAAO,QAAQ,CAAC;iBACnB;AACJ,aAAA,CAAC,CAAC;SACN;AAED,QAAA,OAAO,IAAIC,mBAAY,CAAC,YAAY,CAAC,CAAC;KACzC;AACJ"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { GraphQLRequestContext } from '@apollo/server';
|
|
2
|
-
import * as IORedis from 'ioredis';
|
|
3
|
-
import 'isomorphic-fetch';
|
|
4
|
-
import { Express } from 'express';
|
|
5
|
-
import * as http from 'http';
|
|
6
|
-
import { InvalidationKeyGenerator } from '../plugins';
|
|
7
|
-
import { IModuleService } from '../interfaces';
|
|
8
|
-
export type KeyGenerator = (context: GraphQLRequestContext<unknown>, cacheKey?: string) => string;
|
|
9
|
-
export declare class GraphqlServer {
|
|
10
|
-
private app;
|
|
11
|
-
private httpServer;
|
|
12
|
-
private redisClient;
|
|
13
|
-
private moduleService;
|
|
14
|
-
private enableSubscription;
|
|
15
|
-
private readonly cacheKeyGenerator?;
|
|
16
|
-
private readonly invalidateCacheKeyGenerator?;
|
|
17
|
-
private logger;
|
|
18
|
-
private graphqlWsServer;
|
|
19
|
-
constructor(app: Express, httpServer: http.Server, redisClient: IORedis.Redis | IORedis.Cluster, moduleService: IModuleService, enableSubscription?: boolean, cacheKeyGenerator?: KeyGenerator, invalidateCacheKeyGenerator?: InvalidationKeyGenerator);
|
|
20
|
-
initialize(): Promise<void>;
|
|
21
|
-
getUserIpAddress(req: any): any;
|
|
22
|
-
private configureApolloServer;
|
|
23
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import {ApolloServer}from'@apollo/server';import {expressMiddleware}from'@apollo/server/express4';import {ApolloServerPluginCacheControl}from'@apollo/server/plugin/cacheControl';import {ApolloServerPluginDrainHttpServer}from'@apollo/server/plugin/drainHttpServer';import'isomorphic-fetch';import express from'express';import cors from'cors';import Keyv from'keyv';import KeyvRedis from'@keyv/redis';import {KeyvAdapter}from'@apollo/utils.keyvadapter';import {WebSocketServer}from'ws';import {invalidateCachePlugin}from'../plugins/invalidateCachePlugin.mjs';import {responseCachePlugin}from'../plugins/responseCachePlugin.mjs';import {GraphqlWs}from'./GraphqlWs.mjs';import {config}from'../config/env-config.mjs';if ((process.env.LOG_LEVEL && process.env.LOG_LEVEL === 'trace') || process.env.LOG_LEVEL === 'debug') ;
|
|
2
|
-
// @workaround as the `dataSources` not available in Subscription (websocket) Context.
|
|
3
|
-
// https://github.com/apollographql/apollo-server/issues/1526 need to revisit in Apollo-Server v3.
|
|
4
|
-
const constructDataSourcesForSubscriptions = (context, cache, dataSources) => {
|
|
5
|
-
const initializeDataSource = (instance) => {
|
|
6
|
-
instance.initialize({ context, cache });
|
|
7
|
-
};
|
|
8
|
-
for (const prop in dataSources) {
|
|
9
|
-
initializeDataSource(dataSources[prop]);
|
|
10
|
-
}
|
|
11
|
-
return dataSources;
|
|
12
|
-
};
|
|
13
|
-
class GraphqlServer {
|
|
14
|
-
app;
|
|
15
|
-
httpServer;
|
|
16
|
-
redisClient;
|
|
17
|
-
moduleService;
|
|
18
|
-
enableSubscription;
|
|
19
|
-
cacheKeyGenerator;
|
|
20
|
-
invalidateCacheKeyGenerator;
|
|
21
|
-
logger;
|
|
22
|
-
graphqlWsServer;
|
|
23
|
-
constructor(app, httpServer, redisClient, moduleService, enableSubscription = true, cacheKeyGenerator, invalidateCacheKeyGenerator) {
|
|
24
|
-
this.app = app;
|
|
25
|
-
this.httpServer = httpServer;
|
|
26
|
-
this.redisClient = redisClient;
|
|
27
|
-
this.moduleService = moduleService;
|
|
28
|
-
this.enableSubscription = enableSubscription;
|
|
29
|
-
this.cacheKeyGenerator = cacheKeyGenerator;
|
|
30
|
-
this.invalidateCacheKeyGenerator = invalidateCacheKeyGenerator;
|
|
31
|
-
this.logger = this.moduleService.logger.child({ className: 'GraphqlServer' });
|
|
32
|
-
if (enableSubscription) {
|
|
33
|
-
const wsServer = new WebSocketServer({
|
|
34
|
-
server: this.httpServer,
|
|
35
|
-
path: config.GRAPHQL_ENDPOINT,
|
|
36
|
-
});
|
|
37
|
-
this.graphqlWsServer = new GraphqlWs(wsServer, this.moduleService, this.redisClient);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
async initialize() {
|
|
41
|
-
this.logger.info('GraphqlServer initializing...');
|
|
42
|
-
this.graphqlWsServer.create();
|
|
43
|
-
const apolloServer = this.configureApolloServer();
|
|
44
|
-
await apolloServer.start();
|
|
45
|
-
const corsOptions = {
|
|
46
|
-
origin: [config.CLIENT_URL],
|
|
47
|
-
credentials: true,
|
|
48
|
-
};
|
|
49
|
-
this.app.use(__GRAPHQL_ENDPOINT__, cors(corsOptions), express.json(), expressMiddleware(apolloServer, {
|
|
50
|
-
context: async ({ req, res, connection }) => {
|
|
51
|
-
let context;
|
|
52
|
-
let addons = {};
|
|
53
|
-
const dataSources = this.moduleService.dataSource;
|
|
54
|
-
try {
|
|
55
|
-
if (connection) {
|
|
56
|
-
context = connection.context;
|
|
57
|
-
if (!context.dataSources) {
|
|
58
|
-
addons = {
|
|
59
|
-
dataSources: constructDataSourcesForSubscriptions(connection.context, this.redisClient, dataSources),
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
addons = {
|
|
64
|
-
dataSources,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
const pureContext = await this.moduleService.createContext(req, res);
|
|
70
|
-
const contextServices = await this.moduleService.serviceContext(req, res);
|
|
71
|
-
context = {
|
|
72
|
-
...pureContext,
|
|
73
|
-
...contextServices,
|
|
74
|
-
preferences: this.moduleService.defaultPreferences,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
context.userIp = this.getUserIpAddress(req);
|
|
78
|
-
}
|
|
79
|
-
catch (err) {
|
|
80
|
-
this.logger.error(err, 'adding context to graphql failed due to [%s]', err.message);
|
|
81
|
-
throw err;
|
|
82
|
-
}
|
|
83
|
-
return {
|
|
84
|
-
req,
|
|
85
|
-
res,
|
|
86
|
-
dataSources,
|
|
87
|
-
...context,
|
|
88
|
-
...addons,
|
|
89
|
-
};
|
|
90
|
-
},
|
|
91
|
-
}));
|
|
92
|
-
this.logger.info('GraphqlServer initialized - ', config.CLIENT_URL);
|
|
93
|
-
}
|
|
94
|
-
getUserIpAddress(req) {
|
|
95
|
-
let ip = (req?.headers['x-forwarded-for'] || '').split(',')[0] || req?.connection?.remoteAddress;
|
|
96
|
-
if (ip.substr(0, 7) === '::ffff:') {
|
|
97
|
-
ip = ip.substr(7);
|
|
98
|
-
}
|
|
99
|
-
if (ip === '::1') {
|
|
100
|
-
ip = '127.0.0.1';
|
|
101
|
-
}
|
|
102
|
-
return ip;
|
|
103
|
-
}
|
|
104
|
-
configureApolloServer() {
|
|
105
|
-
const redisStore = new KeyvRedis(this.redisClient);
|
|
106
|
-
redisStore.on('error', (err) => {
|
|
107
|
-
this.logger.error(err, 'Redis connection error:');
|
|
108
|
-
});
|
|
109
|
-
const keyvCache = new Keyv({ store: redisStore, namespace: config.APP_NAME });
|
|
110
|
-
const cacheAdapter = new KeyvAdapter(keyvCache);
|
|
111
|
-
const cacheGet = cacheAdapter.get.bind(cacheAdapter);
|
|
112
|
-
cacheAdapter.get = (key) => cacheGet(key.replaceAll('fqc:', ''));
|
|
113
|
-
const cacheSet = cacheAdapter.set.bind(cacheAdapter);
|
|
114
|
-
cacheAdapter.set = (key, value, opts) => cacheSet(key.replaceAll('fqc:', ''), value, opts);
|
|
115
|
-
const { cacheKeyGenerator, invalidateCacheKeyGenerator, logger } = this;
|
|
116
|
-
const serverConfig = {
|
|
117
|
-
schema: this.moduleService.schema,
|
|
118
|
-
allowBatchedHttpRequests: true,
|
|
119
|
-
cache: cacheAdapter,
|
|
120
|
-
plugins: [
|
|
121
|
-
ApolloServerPluginDrainHttpServer({ httpServer: this.httpServer }),
|
|
122
|
-
ApolloServerPluginCacheControl(),
|
|
123
|
-
invalidateCachePlugin({ cache: this.redisClient, invalidateCacheKeyGenerator }),
|
|
124
|
-
responseCachePlugin({ logger, cacheKeyGenerator }),
|
|
125
|
-
],
|
|
126
|
-
};
|
|
127
|
-
if (this.enableSubscription) {
|
|
128
|
-
serverConfig.plugins.push({
|
|
129
|
-
async serverWillStart() {
|
|
130
|
-
const response = {
|
|
131
|
-
async drainServer() {
|
|
132
|
-
await this?.graphqlWsServer?.disconnect();
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
response.drainServer.bind(this);
|
|
136
|
-
return response;
|
|
137
|
-
},
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
return new ApolloServer(serverConfig);
|
|
141
|
-
}
|
|
142
|
-
}export{GraphqlServer};//# sourceMappingURL=GraphqlServer.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GraphqlServer.mjs","sources":["../../src/servers/GraphqlServer.ts"],"sourcesContent":[null],"names":[],"mappings":"wsBAsBA,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,SAAS,KAAK,OAAO,KAAK,OAAO,CAAC,GAAG,CAAC,SAAS,KAAK,OAAO,EAAE,CAEtG;AAED;AACA;AACA,MAAM,oCAAoC,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,WAAW,KAAI;AACzE,IAAA,MAAM,oBAAoB,GAAG,CAAC,QAAQ,KAAI;QACtC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;AAC5C,KAAC,CAAC;AACF,IAAA,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE;AAC5B,QAAA,oBAAoB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;KAC3C;AACD,IAAA,OAAO,WAAW,CAAC;AACvB,CAAC,CAAC;MAIW,aAAa,CAAA;AAMV,IAAA,GAAA,CAAA;AACA,IAAA,UAAA,CAAA;AACA,IAAA,WAAA,CAAA;AACA,IAAA,aAAA,CAAA;AACA,IAAA,kBAAA,CAAA;AACS,IAAA,iBAAA,CAAA;AACA,IAAA,2BAAA,CAAA;AAXb,IAAA,MAAM,CAAU;AAEhB,IAAA,eAAe,CAAmB;AAE1C,IAAA,WAAA,CACY,GAAY,EACZ,UAAuB,EACvB,WAA4C,EAC5C,aAA6B,EAC7B,kBAAqB,GAAA,IAAI,EAChB,iBAAgC,EAChC,2BAAsD,EAAA;QAN/D,IAAG,CAAA,GAAA,GAAH,GAAG,CAAS;QAC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ACnB;AACJ,aAAA,CAAC,CAAC;SACN;AAED,QAAA,OAAO,IAAI,YAAY,CAAC,YAAY,CAAC,CAAC;KACzC;AACJ"}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
'use strict';var ws=require('graphql-ws/lib/use/ws');require('graphql');// @workaround as the `dataSources` not available in Subscription (websocket) Context.
|
|
2
|
-
// https://github.com/apollographql/apollo-server/issues/1526 need to revisit in Apollo-Server v3.
|
|
3
|
-
const constructDataSourcesForSubscriptions = (context, cache, dataSources) => {
|
|
4
|
-
const intializeDataSource = (instance) => {
|
|
5
|
-
instance.initialize({ context, cache });
|
|
6
|
-
};
|
|
7
|
-
// tslint:disable-next-line:forin
|
|
8
|
-
for (const prop in dataSources) {
|
|
9
|
-
if (dataSources[prop] && typeof dataSources[prop]?.initialize === 'function') {
|
|
10
|
-
intializeDataSource(dataSources[prop]);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return dataSources;
|
|
14
|
-
};
|
|
15
|
-
class GraphqlWs {
|
|
16
|
-
wsServer;
|
|
17
|
-
moduleService;
|
|
18
|
-
cache;
|
|
19
|
-
subscriptionServer;
|
|
20
|
-
logger;
|
|
21
|
-
constructor(wsServer, moduleService, cache) {
|
|
22
|
-
this.wsServer = wsServer;
|
|
23
|
-
this.moduleService = moduleService;
|
|
24
|
-
this.cache = cache;
|
|
25
|
-
this.logger = this.moduleService.logger;
|
|
26
|
-
}
|
|
27
|
-
create() {
|
|
28
|
-
this.subscriptionServer = ws.useServer({
|
|
29
|
-
schema: this.moduleService.schema,
|
|
30
|
-
// Adding a context property lets you add data to your GraphQL operation context
|
|
31
|
-
context: async (ctx) => {
|
|
32
|
-
// Returning an object here will add that information to our
|
|
33
|
-
// GraphQL context, which all of our resolvers have access to.
|
|
34
|
-
// ctx is the `graphql-ws` Context where connectionParams live
|
|
35
|
-
try {
|
|
36
|
-
const pureContext = await this.moduleService.createContext(ctx.connectionParams, null);
|
|
37
|
-
const contextServices = await this.moduleService.serviceContext(ctx.connectionParams, null);
|
|
38
|
-
const context = {
|
|
39
|
-
...contextServices,
|
|
40
|
-
...pureContext,
|
|
41
|
-
preferences: this.moduleService.defaultPreferences,
|
|
42
|
-
// update: updateContainers,
|
|
43
|
-
...ctx,
|
|
44
|
-
};
|
|
45
|
-
const addons = {
|
|
46
|
-
dataSources: constructDataSourcesForSubscriptions(context, this.cache, this.moduleService.dataSource),
|
|
47
|
-
};
|
|
48
|
-
return {
|
|
49
|
-
...context,
|
|
50
|
-
...addons,
|
|
51
|
-
...ctx,
|
|
52
|
-
...pureContext,
|
|
53
|
-
preferences: this.moduleService.defaultPreferences,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
catch (err) {
|
|
57
|
-
this.logger.error(err);
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
// onConnect: async (ctx) => {
|
|
61
|
-
// // do anything when connected
|
|
62
|
-
// },
|
|
63
|
-
// onOperation: (ctx, msg) => {
|
|
64
|
-
// }
|
|
65
|
-
// onOperation: async (message: { payload: any }, connection: ExecutionParams) => {
|
|
66
|
-
// connection.formatResponse = (value: ExecutionResult) => ({
|
|
67
|
-
// ...value,
|
|
68
|
-
// errors:
|
|
69
|
-
// value.errors &&
|
|
70
|
-
// formatApolloErrors([...value.errors], {
|
|
71
|
-
// formatter: this.requestOptions.formatError,
|
|
72
|
-
// debug: this.requestOptions.debug,
|
|
73
|
-
// }),
|
|
74
|
-
// });
|
|
75
|
-
// let context: Context = this.context ? this.context : { connection };
|
|
76
|
-
// try {
|
|
77
|
-
// context =
|
|
78
|
-
// typeof this.context === 'function'
|
|
79
|
-
// ? await this.context({ connection, payload: message.payload })
|
|
80
|
-
// : context;
|
|
81
|
-
// } catch (e) {
|
|
82
|
-
// throw formatApolloErrors([e], {
|
|
83
|
-
// formatter: this.requestOptions.formatError,
|
|
84
|
-
// debug: this.requestOptions.debug,
|
|
85
|
-
// })[0];
|
|
86
|
-
// }
|
|
87
|
-
// return { ...connection }; // TODO: we didn't add `context`
|
|
88
|
-
// },
|
|
89
|
-
}, this.wsServer);
|
|
90
|
-
return this.subscriptionServer;
|
|
91
|
-
}
|
|
92
|
-
disconnect() {
|
|
93
|
-
if (this.subscriptionServer) {
|
|
94
|
-
this.subscriptionServer.dispose();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}exports.GraphqlWs=GraphqlWs;//# sourceMappingURL=GraphqlWs.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GraphqlWs.cjs","sources":["../../src/servers/GraphqlWs.ts"],"sourcesContent":[null],"names":["useServer"],"mappings":"wEAUA;AACA;AACA,MAAM,oCAAoC,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,WAAW,KAAI;AACzE,IAAA,MAAM,mBAAmB,GAAG,CAAC,QAAQ,KAAI;QACrC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;AAC5C,KAAC,CAAC;;AAEF,IAAA,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE;AAC5B,QAAA,IAAI,WAAW,CAAC,IAAI,CAAC,IAAI,OAAO,WAAW,CAAC,IAAI,CAAC,EAAE,UAAU,KAAK,UAAU,EAAE;AAC1E,YAAA,mBAAmB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;SAC1C;KACJ;AACD,IAAA,OAAO,WAAW,CAAC;AACvB,CAAC,CAAC;MA0CW,SAAS,CAAA;AAMN,IAAA,QAAA,CAAA;AACA,IAAA,aAAA,CAAA;AACE,IAAA,KAAA,CAAA;AAPN,IAAA,kBAAkB,CAAa;AAE/B,IAAA,MAAM,CAAU;AAExB,IAAA,WAAA,CACY,QAAyB,EACzB,aAA6B,EAC3B,KAAsC,EAAA;QAFxC,IAAQ,CAAA,QAAA,GAAR,QAAQ,CAAiB;QACzB,IAAa,CAAA,aAAA,GAAb,aAAa,CAAgB;QAC3B,IAAK,CAAA,KAAA,GAAL,KAAK,CAAiC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AAkB,CAAC;KAClC;IAEM,UAAU,GAAA;AACb,QAAA,IAAI,IAAI,CAAC,kBAAkB,EAAE;AACzB,YAAA,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,CAAC;SACrC;KACJ;AACJ"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as IORedis from 'ioredis';
|
|
2
|
-
import { Disposable } from 'graphql-ws';
|
|
3
|
-
import { WebSocketServer } from 'ws';
|
|
4
|
-
import { IModuleService } from '../interfaces';
|
|
5
|
-
export declare class GraphqlWs {
|
|
6
|
-
private wsServer;
|
|
7
|
-
private moduleService;
|
|
8
|
-
protected cache: IORedis.Redis | IORedis.Cluster;
|
|
9
|
-
private subscriptionServer;
|
|
10
|
-
private logger;
|
|
11
|
-
constructor(wsServer: WebSocketServer, moduleService: IModuleService, cache: IORedis.Redis | IORedis.Cluster);
|
|
12
|
-
create(): Disposable;
|
|
13
|
-
disconnect(): void;
|
|
14
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import {useServer}from'graphql-ws/lib/use/ws';import'graphql';// @workaround as the `dataSources` not available in Subscription (websocket) Context.
|
|
2
|
-
// https://github.com/apollographql/apollo-server/issues/1526 need to revisit in Apollo-Server v3.
|
|
3
|
-
const constructDataSourcesForSubscriptions = (context, cache, dataSources) => {
|
|
4
|
-
const intializeDataSource = (instance) => {
|
|
5
|
-
instance.initialize({ context, cache });
|
|
6
|
-
};
|
|
7
|
-
// tslint:disable-next-line:forin
|
|
8
|
-
for (const prop in dataSources) {
|
|
9
|
-
if (dataSources[prop] && typeof dataSources[prop]?.initialize === 'function') {
|
|
10
|
-
intializeDataSource(dataSources[prop]);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return dataSources;
|
|
14
|
-
};
|
|
15
|
-
class GraphqlWs {
|
|
16
|
-
wsServer;
|
|
17
|
-
moduleService;
|
|
18
|
-
cache;
|
|
19
|
-
subscriptionServer;
|
|
20
|
-
logger;
|
|
21
|
-
constructor(wsServer, moduleService, cache) {
|
|
22
|
-
this.wsServer = wsServer;
|
|
23
|
-
this.moduleService = moduleService;
|
|
24
|
-
this.cache = cache;
|
|
25
|
-
this.logger = this.moduleService.logger;
|
|
26
|
-
}
|
|
27
|
-
create() {
|
|
28
|
-
this.subscriptionServer = useServer({
|
|
29
|
-
schema: this.moduleService.schema,
|
|
30
|
-
// Adding a context property lets you add data to your GraphQL operation context
|
|
31
|
-
context: async (ctx) => {
|
|
32
|
-
// Returning an object here will add that information to our
|
|
33
|
-
// GraphQL context, which all of our resolvers have access to.
|
|
34
|
-
// ctx is the `graphql-ws` Context where connectionParams live
|
|
35
|
-
try {
|
|
36
|
-
const pureContext = await this.moduleService.createContext(ctx.connectionParams, null);
|
|
37
|
-
const contextServices = await this.moduleService.serviceContext(ctx.connectionParams, null);
|
|
38
|
-
const context = {
|
|
39
|
-
...contextServices,
|
|
40
|
-
...pureContext,
|
|
41
|
-
preferences: this.moduleService.defaultPreferences,
|
|
42
|
-
// update: updateContainers,
|
|
43
|
-
...ctx,
|
|
44
|
-
};
|
|
45
|
-
const addons = {
|
|
46
|
-
dataSources: constructDataSourcesForSubscriptions(context, this.cache, this.moduleService.dataSource),
|
|
47
|
-
};
|
|
48
|
-
return {
|
|
49
|
-
...context,
|
|
50
|
-
...addons,
|
|
51
|
-
...ctx,
|
|
52
|
-
...pureContext,
|
|
53
|
-
preferences: this.moduleService.defaultPreferences,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
catch (err) {
|
|
57
|
-
this.logger.error(err);
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
// onConnect: async (ctx) => {
|
|
61
|
-
// // do anything when connected
|
|
62
|
-
// },
|
|
63
|
-
// onOperation: (ctx, msg) => {
|
|
64
|
-
// }
|
|
65
|
-
// onOperation: async (message: { payload: any }, connection: ExecutionParams) => {
|
|
66
|
-
// connection.formatResponse = (value: ExecutionResult) => ({
|
|
67
|
-
// ...value,
|
|
68
|
-
// errors:
|
|
69
|
-
// value.errors &&
|
|
70
|
-
// formatApolloErrors([...value.errors], {
|
|
71
|
-
// formatter: this.requestOptions.formatError,
|
|
72
|
-
// debug: this.requestOptions.debug,
|
|
73
|
-
// }),
|
|
74
|
-
// });
|
|
75
|
-
// let context: Context = this.context ? this.context : { connection };
|
|
76
|
-
// try {
|
|
77
|
-
// context =
|
|
78
|
-
// typeof this.context === 'function'
|
|
79
|
-
// ? await this.context({ connection, payload: message.payload })
|
|
80
|
-
// : context;
|
|
81
|
-
// } catch (e) {
|
|
82
|
-
// throw formatApolloErrors([e], {
|
|
83
|
-
// formatter: this.requestOptions.formatError,
|
|
84
|
-
// debug: this.requestOptions.debug,
|
|
85
|
-
// })[0];
|
|
86
|
-
// }
|
|
87
|
-
// return { ...connection }; // TODO: we didn't add `context`
|
|
88
|
-
// },
|
|
89
|
-
}, this.wsServer);
|
|
90
|
-
return this.subscriptionServer;
|
|
91
|
-
}
|
|
92
|
-
disconnect() {
|
|
93
|
-
if (this.subscriptionServer) {
|
|
94
|
-
this.subscriptionServer.dispose();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}export{GraphqlWs};//# sourceMappingURL=GraphqlWs.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GraphqlWs.mjs","sources":["../../src/servers/GraphqlWs.ts"],"sourcesContent":[null],"names":[],"mappings":"8DAUA;AACA;AACA,MAAM,oCAAoC,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,WAAW,KAAI;AACzE,IAAA,MAAM,mBAAmB,GAAG,CAAC,QAAQ,KAAI;QACrC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;AAC5C,KAAC,CAAC;;AAEF,IAAA,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE;AAC5B,QAAA,IAAI,WAAW,CAAC,IAAI,CAAC,IAAI,OAAO,WAAW,CAAC,IAAI,CAAC,EAAE,UAAU,KAAK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,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,aAAa,CAAC,UAAU,CAChC;qBACJ,CAAC;oBACF,OAAO;AACH,wBAAA,GAAG,OAAO;AACV,wBAAA,GAAG,MAAM;AACT,wBAAA,GAAG,GAAG;AACN,wBAAA,GAAG,WAAW;AACd,wBAAA,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,kBAAkB;qBACrD,CAAC;iBACL;gBAAC,OAAO,GAAG,EAAE;AACV,oBAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;iBAC1B;aACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCJ,SAAA,EACD,IAAI,CAAC,QAAQ,CAChB,CAAC;QACF,OAAO,IAAI,CAAC,kBAAkB,CAAC;KAClC;IAEM,UAAU,GAAA;AACb,QAAA,IAAI,IAAI,CAAC,kBAAkB,EAAE;AACzB,YAAA,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,CAAC;SACrC;KACJ;AACJ"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
'use strict';var url=require('url'),ws=require('ws'),ws$1=require('graphql-ws/lib/use/ws');function _interopNamespaceDefault(e){var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var url__namespace=/*#__PURE__*/_interopNamespaceDefault(url);class WebsocketMultiPathServer {
|
|
2
|
-
moduleService;
|
|
3
|
-
cache;
|
|
4
|
-
webSockets = {};
|
|
5
|
-
// private graphqlSubscriptionServer: GraphqlSubscriptionServer;
|
|
6
|
-
_graphqlWs;
|
|
7
|
-
constructor(moduleService, cache, multiplePathConfig) {
|
|
8
|
-
this.moduleService = moduleService;
|
|
9
|
-
this.cache = cache;
|
|
10
|
-
this._graphqlWs = new ws.WebSocketServer({ noServer: true, path: __GRAPHQL_ENDPOINT__ });
|
|
11
|
-
this.webSockets[__GRAPHQL_ENDPOINT__] = this._graphqlWs;
|
|
12
|
-
this.webSockets[__GRAPHQL_ENDPOINT__].on('connection', (ws, request) => {
|
|
13
|
-
console.log('--REQUESTED CONNECTION--', this._graphqlWs);
|
|
14
|
-
ws$1.useServer({
|
|
15
|
-
schema: moduleService.schema,
|
|
16
|
-
}, this._graphqlWs);
|
|
17
|
-
});
|
|
18
|
-
for (let key in multiplePathConfig) {
|
|
19
|
-
if (!multiplePathConfig.hasOwnProperty(key)) {
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
if (!this.webSockets[key]) {
|
|
23
|
-
this.webSockets[key] = new ws.WebSocketServer({ noServer: true });
|
|
24
|
-
this.webSockets[key].on('connection', (ws, request) => {
|
|
25
|
-
Promise.all([
|
|
26
|
-
moduleService.createContext(request, null),
|
|
27
|
-
moduleService.serviceContext(request, null),
|
|
28
|
-
]).then(multiplePathConfig[key](ws));
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
httpServerUpgrade(httpServer) {
|
|
34
|
-
httpServer.on('upgrade', (request, socket, head) => {
|
|
35
|
-
const pathname = url__namespace.parse(request.url).pathname;
|
|
36
|
-
console.log('--UPGRADE', request.url);
|
|
37
|
-
if (!this.webSockets[pathname]) {
|
|
38
|
-
// in development
|
|
39
|
-
if (pathname !== '/sockjs-node') {
|
|
40
|
-
// need to destroy
|
|
41
|
-
socket.destroy();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
// code to run when a new connection is made
|
|
45
|
-
this.webSockets[pathname].handleUpgrade(request, socket, head, (ws) => {
|
|
46
|
-
this.webSockets[pathname].emit('connection', ws, request);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
// (new GraphqlWs(this.graphqlWs, this.moduleService, this.cache)).create();
|
|
50
|
-
// useServer({
|
|
51
|
-
// schema: this.moduleService.schema,
|
|
52
|
-
// }, this.graphqlWs);
|
|
53
|
-
return httpServer;
|
|
54
|
-
}
|
|
55
|
-
get graphqlWs() {
|
|
56
|
-
return this._graphqlWs;
|
|
57
|
-
}
|
|
58
|
-
close() {
|
|
59
|
-
for (const key in this.webSockets) {
|
|
60
|
-
this.webSockets[key].close();
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}exports.WebsocketMultiPathServer=WebsocketMultiPathServer;//# sourceMappingURL=WebsocketMultipathUpdate.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WebsocketMultipathUpdate.cjs","sources":["../../src/servers/WebsocketMultipathUpdate.ts"],"sourcesContent":[null],"names":["WebSocketServer","useServer","url"],"mappings":"6bAgBa,wBAAwB,CAAA;AAKtB,IAAA,aAAA,CAAA;AACA,IAAA,KAAA,CAAA;IALH,UAAU,GAAoB,EAAE,CAAC;;AAEjC,IAAA,UAAU,CAAkB;AACpC,IAAA,WAAA,CACW,aAA6B,EAC7B,KAAsC,EAC7C,kBAAyC,EAAA;QAFlC,IAAa,CAAA,aAAA,GAAb,aAAa,CAAgB;QAC7B,IAAK,CAAA,KAAA,GAAL,KAAK,CAAiC;AAG7C,QAAA,IAAI,CAAC,UAAU,GAAG,IAAIA,kBAAe,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,oBAAoB,EAAE,CAAC,CAAC;QACtF,IAAI,CAAC,UAAU,CAAC,oBAAoB,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC;AACxD,QAAA,IAAI,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC,EAAE,EAAE,OAAO,KAAI;YACnE,OAAO,CAAC,GAAG,CAAC,0BAA0B,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;AACzD,YAAAC,cAAS,CACL;gBACI,MAAM,EAAE,aAAa,CAAC,MAAM;AAC/B,aAAA,EACD,IAAI,CAAC,UAAU,CAClB,CAAC;AACN,SAAC,CAAC,CAAC;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,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,KAAI;AAClE,gBAAA,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;AAC9D,aAAC,CAAC,CAAC;AACP,SAAC,CAAC,CAAC;;;;;AAOH,QAAA,OAAO,UAAU,CAAC;KACrB;AAED,IAAA,IAAW,SAAS,GAAA;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC;KAC1B;IACM,KAAK,GAAA;AACR,QAAA,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,UAAU,EAAE;YAC/B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;SAChC;KACJ;AACJ"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { WebSocketServer } from 'ws';
|
|
2
|
-
import { Server } from 'http';
|
|
3
|
-
import * as IORedis from 'ioredis';
|
|
4
|
-
import { IModuleService } from '../interfaces';
|
|
5
|
-
interface MultiWebsocketConfig {
|
|
6
|
-
[key: string]: any;
|
|
7
|
-
}
|
|
8
|
-
export declare class WebsocketMultiPathServer {
|
|
9
|
-
moduleService: IModuleService;
|
|
10
|
-
cache: IORedis.Redis | IORedis.Cluster;
|
|
11
|
-
private webSockets;
|
|
12
|
-
private _graphqlWs;
|
|
13
|
-
constructor(moduleService: IModuleService, cache: IORedis.Redis | IORedis.Cluster, multiplePathConfig?: MultiWebsocketConfig);
|
|
14
|
-
httpServerUpgrade(httpServer: Server): Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
|
|
15
|
-
get graphqlWs(): WebSocketServer;
|
|
16
|
-
close(): void;
|
|
17
|
-
}
|
|
18
|
-
export {};
|