@common-stack/server-stack 7.0.4-alpha.17 → 7.0.4-alpha.18
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/lib/MainStackServer.cjs +231 -0
- package/lib/MainStackServer.cjs.map +1 -0
- package/lib/MainStackServer.d.ts +28 -0
- package/lib/MainStackServer.mjs +231 -0
- package/lib/MainStackServer.mjs.map +1 -0
- package/lib/StackServer.cjs +92 -0
- package/lib/StackServer.cjs.map +1 -0
- package/lib/StackServer.d.ts +20 -0
- package/lib/StackServer.mjs +92 -0
- package/lib/StackServer.mjs.map +1 -0
- package/lib/api/remote-config.cjs +6 -0
- package/lib/api/remote-config.cjs.map +1 -0
- package/lib/api/remote-config.d.ts +6 -0
- package/lib/api/remote-config.mjs +6 -0
- package/lib/api/remote-config.mjs.map +1 -0
- package/lib/api/resolver.cjs +12 -0
- package/lib/api/resolver.cjs.map +1 -0
- package/lib/api/resolver.d.ts +10 -0
- package/lib/api/resolver.mjs +12 -0
- package/lib/api/resolver.mjs.map +1 -0
- package/lib/api/root-schema.graphqls.cjs +2 -0
- package/lib/api/root-schema.graphqls.cjs.map +1 -0
- package/lib/api/root-schema.graphqls.mjs +2 -0
- package/lib/api/root-schema.graphqls.mjs.map +1 -0
- package/lib/api/scalar.cjs +16 -0
- package/lib/api/scalar.cjs.map +1 -0
- package/lib/api/scalar.d.ts +2 -0
- package/lib/api/scalar.mjs +16 -0
- package/lib/api/scalar.mjs.map +1 -0
- package/lib/api/schema-builder.cjs +160 -0
- package/lib/api/schema-builder.cjs.map +1 -0
- package/lib/api/schema-builder.d.ts +24 -0
- package/lib/api/schema-builder.mjs +160 -0
- package/lib/api/schema-builder.mjs.map +1 -0
- package/lib/api/utils.cjs +27 -0
- package/lib/api/utils.cjs.map +1 -0
- package/lib/api/utils.d.ts +4 -0
- package/lib/api/utils.mjs +27 -0
- package/lib/api/utils.mjs.map +1 -0
- package/lib/config/env-config.cjs +38 -0
- package/lib/config/env-config.cjs.map +1 -0
- package/lib/config/env-config.d.ts +21 -0
- package/lib/config/env-config.mjs +38 -0
- package/lib/config/env-config.mjs.map +1 -0
- package/lib/config/index.d.ts +1 -0
- package/lib/config/moleculer.config.cjs +191 -0
- package/lib/config/moleculer.config.cjs.map +1 -0
- package/lib/config/moleculer.config.d.ts +20 -0
- package/lib/config/moleculer.config.mjs +191 -0
- package/lib/config/moleculer.config.mjs.map +1 -0
- package/lib/connectors/connection-broker.cjs +61 -0
- package/lib/connectors/connection-broker.cjs.map +1 -0
- package/lib/connectors/connection-broker.d.ts +26 -0
- package/lib/connectors/connection-broker.mjs +61 -0
- package/lib/connectors/connection-broker.mjs.map +1 -0
- package/lib/connectors/graphql-pubsub-connector.cjs +28 -0
- package/lib/connectors/graphql-pubsub-connector.cjs.map +1 -0
- package/lib/connectors/graphql-pubsub-connector.d.ts +22 -0
- package/lib/connectors/graphql-pubsub-connector.mjs +28 -0
- package/lib/connectors/graphql-pubsub-connector.mjs.map +1 -0
- package/lib/connectors/mongo-connector.cjs +57 -0
- package/lib/connectors/mongo-connector.cjs.map +1 -0
- package/lib/connectors/mongo-connector.d.ts +21 -0
- package/lib/connectors/mongo-connector.mjs +57 -0
- package/lib/connectors/mongo-connector.mjs.map +1 -0
- package/lib/connectors/nats-connector.cjs +63 -0
- package/lib/connectors/nats-connector.cjs.map +1 -0
- package/lib/connectors/nats-connector.d.ts +20 -0
- package/lib/connectors/nats-connector.mjs +63 -0
- package/lib/connectors/nats-connector.mjs.map +1 -0
- package/lib/connectors/redis-connector.cjs +79 -0
- package/lib/connectors/redis-connector.cjs.map +1 -0
- package/lib/connectors/redis-connector.d.ts +30 -0
- package/lib/connectors/redis-connector.mjs +79 -0
- package/lib/connectors/redis-connector.mjs.map +1 -0
- package/lib/graphql/directives/index.cjs +10 -0
- package/lib/graphql/directives/index.cjs.map +1 -0
- package/lib/graphql/directives/index.d.ts +7 -0
- package/lib/graphql/directives/index.mjs +10 -0
- package/lib/graphql/directives/index.mjs.map +1 -0
- package/lib/graphql/index.d.ts +2 -0
- package/lib/graphql/schema/directives.graphql.cjs +1 -0
- package/lib/graphql/schema/directives.graphql.cjs.map +1 -0
- package/lib/graphql/schema/directives.graphql.mjs +1 -0
- package/lib/graphql/schema/directives.graphql.mjs.map +1 -0
- package/lib/graphql/schema/index.cjs +1 -0
- package/lib/graphql/schema/index.cjs.map +1 -0
- package/lib/graphql/schema/index.d.ts +1 -0
- package/lib/graphql/schema/index.mjs +1 -0
- package/lib/graphql/schema/index.mjs.map +1 -0
- package/lib/index.cjs +1 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.mjs +1 -0
- package/lib/index.mjs.map +1 -0
- package/lib/interfaces/dbMigration.d.ts +8 -0
- package/lib/interfaces/graphql-request-context.d.ts +15 -0
- package/lib/interfaces/index.d.ts +4 -0
- package/lib/interfaces/module-interface.d.ts +13 -0
- package/lib/interfaces/moleculer.d.ts +7 -0
- package/lib/middleware/cors.cjs +26 -0
- package/lib/middleware/cors.cjs.map +1 -0
- package/lib/middleware/cors.d.ts +6 -0
- package/lib/middleware/cors.mjs +26 -0
- package/lib/middleware/cors.mjs.map +1 -0
- package/lib/middleware/error.cjs +18 -0
- package/lib/middleware/error.cjs.map +1 -0
- package/lib/middleware/error.d.ts +9 -0
- package/lib/middleware/error.mjs +18 -0
- package/lib/middleware/error.mjs.map +1 -0
- package/lib/middleware/moleculer-inter-namespace.cjs +44 -0
- package/lib/middleware/moleculer-inter-namespace.cjs.map +1 -0
- package/lib/middleware/moleculer-inter-namespace.d.ts +2 -0
- package/lib/middleware/moleculer-inter-namespace.mjs +44 -0
- package/lib/middleware/moleculer-inter-namespace.mjs.map +1 -0
- package/lib/middleware/sentry.cjs +3 -0
- package/lib/middleware/sentry.cjs.map +1 -0
- package/lib/middleware/sentry.d.ts +2 -0
- package/lib/middleware/sentry.mjs +3 -0
- package/lib/middleware/sentry.mjs.map +1 -0
- package/lib/middleware/services.cjs +12 -0
- package/lib/middleware/services.cjs.map +1 -0
- package/lib/middleware/services.d.ts +2 -0
- package/lib/middleware/services.mjs +12 -0
- package/lib/middleware/services.mjs.map +1 -0
- package/lib/plugins/index.d.ts +2 -0
- package/lib/plugins/invalidateCachePlugin.cjs +63 -0
- package/lib/plugins/invalidateCachePlugin.cjs.map +1 -0
- package/lib/plugins/invalidateCachePlugin.d.ts +8 -0
- package/lib/plugins/invalidateCachePlugin.mjs +63 -0
- package/lib/plugins/invalidateCachePlugin.mjs.map +1 -0
- package/lib/plugins/invalidateCachePlugin.test.d.ts +1 -0
- package/lib/plugins/response-cache-plugin.test.d.ts +1 -0
- package/lib/plugins/responseCachePlugin.cjs +63 -0
- package/lib/plugins/responseCachePlugin.cjs.map +1 -0
- package/lib/plugins/responseCachePlugin.d.ts +12 -0
- package/lib/plugins/responseCachePlugin.mjs +63 -0
- package/lib/plugins/responseCachePlugin.mjs.map +1 -0
- package/lib/servers/ExpressApp.cjs +37 -0
- package/lib/servers/ExpressApp.cjs.map +1 -0
- package/lib/servers/ExpressApp.d.ts +3 -0
- package/lib/servers/ExpressApp.mjs +37 -0
- package/lib/servers/ExpressApp.mjs.map +1 -0
- package/lib/servers/GraphqlServer.cjs +142 -0
- package/lib/servers/GraphqlServer.cjs.map +1 -0
- package/lib/servers/GraphqlServer.d.ts +23 -0
- package/lib/servers/GraphqlServer.mjs +142 -0
- package/lib/servers/GraphqlServer.mjs.map +1 -0
- package/lib/servers/GraphqlWs.cjs +97 -0
- package/lib/servers/GraphqlWs.cjs.map +1 -0
- package/lib/servers/GraphqlWs.d.ts +14 -0
- package/lib/servers/GraphqlWs.mjs +97 -0
- package/lib/servers/GraphqlWs.mjs.map +1 -0
- package/lib/servers/WebsocketMultipathUpdate.cjs +63 -0
- package/lib/servers/WebsocketMultipathUpdate.cjs.map +1 -0
- package/lib/servers/WebsocketMultipathUpdate.d.ts +18 -0
- package/lib/servers/WebsocketMultipathUpdate.mjs +63 -0
- package/lib/servers/WebsocketMultipathUpdate.mjs.map +1 -0
- package/lib/servers/mongodb-migration-update.d.ts +12 -0
- package/lib/servers/utils.d.ts +14 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/migrations.cjs +26 -0
- package/lib/utils/migrations.cjs.map +1 -0
- package/lib/utils/migrations.d.ts +8 -0
- package/lib/utils/migrations.mjs +26 -0
- package/lib/utils/migrations.mjs.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,142 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,C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,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;gBACL,iCAAiC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC;AAClE,gBAAA,8BAA8B,EAAE;gBAChC,qBAAqB,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,2BAA2B,EAAE,CAAC;AAC/E,gBAAA,mBAAmB,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,IAAI,YAAY,CAAC,YAAY,CAAC,CAAC;KACzC;AACJ"}
|
|
@@ -0,0 +1,97 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GraphqlWs.cjs","sources":["../../src/servers/GraphqlWs.ts"],"sourcesContent":[null],"names":["useServer"],"mappings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vF,oBAAA,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC,GAAG,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;AAC5F,oBAAA,MAAM,OAAO,GAAG;AACZ,wBAAA,GAAG,eAAe;AAClB,wBAAA,GAAG,WAAW;AACd,wBAAA,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,kBAAkB;;AAElD,wBAAA,GAAG,GAAG;qBACT,CAAC;AACF,oBAAA,MAAM,MAAM,GAAG;AACX,wBAAA,WAAW,EAAE,oCAAoC,CAC7C,OAAO,EACP,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"}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,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,CAA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;;;;;;;;;;;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"}
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebsocketMultipathUpdate.cjs","sources":["../../src/servers/WebsocketMultipathUpdate.ts"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IAAI,CAAC,UAAU,EAAE;YAC/B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;SAChC;KACJ;AACJ"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import*as url from'url';import {WebSocketServer}from'ws';import {useServer}from'graphql-ws/lib/use/ws';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 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
|
+
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 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.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
|
+
}export{WebsocketMultiPathServer};//# sourceMappingURL=WebsocketMultipathUpdate.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebsocketMultipathUpdate.mjs","sources":["../../src/servers/WebsocketMultipathUpdate.ts"],"sourcesContent":[null],"names":[],"mappings":"6GAgBa,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,IAAI,eAAe,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,YAAA,SAAS,CACL;gBACI,MAAM,EAAE,aAAa,CAAC,MAAM;AAC/B,aAAA,EACD,IAAI,CAAC,UAAU,CAClB,CAAC;AACN,SAAC,CAAC,CAAC;AAEH,QAAA,KAAK,IAAI,GAAG,IAAI,kBAAkB,EAAE;YAChC,IAAI,CAAC,kBAAkB,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;gBACzC,SAAS;aACZ;YAED,IAAI,CAAC,IAAI,CAAC,UAAU,CAA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AC9D,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"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IModuleService } from '../interfaces';
|
|
2
|
+
import { Schema, Connection as DBConnection } from 'mongoose';
|
|
3
|
+
export declare const MigrationSchema: Schema<any, import("mongoose").Model<any, any, any, any, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, {
|
|
4
|
+
name: string;
|
|
5
|
+
migrated_at?: Date;
|
|
6
|
+
}>;
|
|
7
|
+
export declare class MongoDBMigrationUpgrade {
|
|
8
|
+
private moduleService;
|
|
9
|
+
private mongoDB;
|
|
10
|
+
constructor(moduleService: IModuleService, mongoDB: DBConnection);
|
|
11
|
+
migrate(): Promise<any>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as IORedis from 'ioredis';
|
|
2
|
+
import { CdmLogger } from '@cdm-logger/core';
|
|
3
|
+
type ILogger = CdmLogger.ILogger;
|
|
4
|
+
/**
|
|
5
|
+
* It'll get messy below but there's an issue currently with the state of the protocols that can be used (subscriptions-transport-ws vs graphql-ws).
|
|
6
|
+
* Read more from: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#the-graphql-ws-transport-library
|
|
7
|
+
*
|
|
8
|
+
* Bottomline is, if we use the newer and actively maintained `graphql-ws` lib, then the GraphQL Playground will not work because it uses the old protocol.
|
|
9
|
+
*
|
|
10
|
+
* The approach below tries to support both based on the template provided here but adjusted for our setup here.
|
|
11
|
+
* https://github.com/enisdenjo/graphql-ws#ws-backwards-compat
|
|
12
|
+
*/
|
|
13
|
+
export declare function createContextFromConnectionParams(context: any, datasources: any, cache: IORedis.Redis | IORedis.Cluster, logger: ILogger): Promise<any>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './migrations';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';var mongoose=require('mongoose');const MigrationSchema = new mongoose.Schema({
|
|
2
|
+
migrated_at: Date,
|
|
3
|
+
name: { required: true, type: String },
|
|
4
|
+
});
|
|
5
|
+
async function migrate(db, container, logger) {
|
|
6
|
+
try {
|
|
7
|
+
const migrations = container.getAll('MongodbMigration');
|
|
8
|
+
const model = db.model('Migration', MigrationSchema);
|
|
9
|
+
migrations.map(async (migration) => {
|
|
10
|
+
const exists = await model.findOne({ name: migration.id });
|
|
11
|
+
if (!exists) {
|
|
12
|
+
try {
|
|
13
|
+
await migration.up();
|
|
14
|
+
await model.create({ name: migration.id, migrated_at: new Date() });
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
console.log(`Can not process migration ${migration.id}: `, e);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return migration.id;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
console.warn('ignoring migrate database due to ', err.message);
|
|
25
|
+
}
|
|
26
|
+
}exports.MigrationSchema=MigrationSchema;exports.migrate=migrate;//# sourceMappingURL=migrations.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrations.cjs","sources":["../../src/utils/migrations.ts"],"sourcesContent":[null],"names":["Schema"],"mappings":"8CAKa,MAAA,eAAe,GAAG,IAAIA,eAAM,CAAC;AACtC,IAAA,WAAW,EAAE,IAAI;IACjB,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE;AACzC,CAAA,EAAE;AAEI,eAAe,OAAO,CAAC,EAAc,EAAE,SAAoB,EAAE,MAAyB,EAAA;AACzF,IAAA,IAAI;QACA,MAAM,UAAU,GAAG,SAAS,CAAC,MAAM,CAAqB,kBAAkB,CAAC,CAAC;QAC5E,MAAM,KAAK,GAAG,EAAE,CAAC,KAAK,CAAW,WAAW,EAAE,eAAe,CAAC,CAAC;AAC/D,QAAA,UAAU,CAAC,GAAG,CAAC,OAAO,SAAS,KAAI;AAC/B,YAAA,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC;YAC3D,IAAI,CAAC,MAAM,EAAE;AACT,gBAAA,IAAI;AACA,oBAAA,MAAM,SAAS,CAAC,EAAE,EAAE,CAAC;AACrB,oBAAA,MAAM,KAAK,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,WAAW,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC;iBACvE;gBAAC,OAAO,CAAC,EAAE;oBACR,OAAO,CAAC,GAAG,CAAC,CAA6B,0BAAA,EAAA,SAAS,CAAC,EAAE,CAAI,EAAA,CAAA,EAAE,CAAC,CAAC,CAAC;iBACjE;aACJ;YAED,OAAO,SAAS,CAAC,EAAE,CAAC;AACxB,SAAC,CAAC,CAAC;KACN;IAAC,OAAO,GAAG,EAAE;QACV,OAAO,CAAC,IAAI,CAAC,mCAAmC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;KAClE;AAEL"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Schema, Connection } from 'mongoose';
|
|
2
|
+
import { Container } from 'inversify';
|
|
3
|
+
import { CdmLogger } from '@cdm-logger/core';
|
|
4
|
+
export declare const MigrationSchema: Schema<any, import("mongoose").Model<any, any, any, any, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, {
|
|
5
|
+
name: string;
|
|
6
|
+
migrated_at?: Date;
|
|
7
|
+
}>;
|
|
8
|
+
export declare function migrate(db: Connection, container: Container, logger: CdmLogger.ILogger): Promise<void>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {Schema}from'mongoose';const MigrationSchema = new Schema({
|
|
2
|
+
migrated_at: Date,
|
|
3
|
+
name: { required: true, type: String },
|
|
4
|
+
});
|
|
5
|
+
async function migrate(db, container, logger) {
|
|
6
|
+
try {
|
|
7
|
+
const migrations = container.getAll('MongodbMigration');
|
|
8
|
+
const model = db.model('Migration', MigrationSchema);
|
|
9
|
+
migrations.map(async (migration) => {
|
|
10
|
+
const exists = await model.findOne({ name: migration.id });
|
|
11
|
+
if (!exists) {
|
|
12
|
+
try {
|
|
13
|
+
await migration.up();
|
|
14
|
+
await model.create({ name: migration.id, migrated_at: new Date() });
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
console.log(`Can not process migration ${migration.id}: `, e);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return migration.id;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
console.warn('ignoring migrate database due to ', err.message);
|
|
25
|
+
}
|
|
26
|
+
}export{MigrationSchema,migrate};//# sourceMappingURL=migrations.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrations.mjs","sources":["../../src/utils/migrations.ts"],"sourcesContent":[null],"names":[],"mappings":"8BAKa,MAAA,eAAe,GAAG,IAAI,MAAM,CAAC;AACtC,IAAA,WAAW,EAAE,IAAI;IACjB,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE;AACzC,CAAA,EAAE;AAEI,eAAe,OAAO,CAAC,EAAc,EAAE,SAAoB,EAAE,MAAyB,EAAA;AACzF,IAAA,IAAI;QACA,MAAM,UAAU,GAAG,SAAS,CAAC,MAAM,CAAqB,kBAAkB,CAAC,CAAC;QAC5E,MAAM,KAAK,GAAG,EAAE,CAAC,KAAK,CAAW,WAAW,EAAE,eAAe,CA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