@common-stack/server-stack 6.0.6-alpha.10 → 6.0.6-alpha.106
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 +8 -4
- package/lib/MainStackServer.cjs.map +1 -1
- package/lib/MainStackServer.mjs +8 -4
- package/lib/MainStackServer.mjs.map +1 -1
- package/lib/api/root-schema.graphqls.cjs +1 -1
- package/lib/api/root-schema.graphqls.mjs +1 -1
- package/lib/api/schema-builder.cjs +2 -1
- package/lib/api/schema-builder.cjs.map +1 -1
- package/lib/api/schema-builder.mjs +2 -1
- package/lib/api/schema-builder.mjs.map +1 -1
- package/lib/config/env-config.cjs +1 -0
- package/lib/config/env-config.cjs.map +1 -1
- package/lib/config/env-config.d.ts +1 -0
- package/lib/config/env-config.mjs +1 -0
- package/lib/config/env-config.mjs.map +1 -1
- package/lib/connectors/mongo-connector.cjs +1 -1
- package/lib/connectors/mongo-connector.cjs.map +1 -1
- package/lib/connectors/mongo-connector.mjs +1 -1
- package/lib/connectors/mongo-connector.mjs.map +1 -1
- package/lib/connectors/redis-connector.cjs +1 -1
- package/lib/connectors/redis-connector.cjs.map +1 -1
- package/lib/connectors/redis-connector.mjs +1 -1
- package/lib/connectors/redis-connector.mjs.map +1 -1
- 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/middleware/error.cjs +2 -32
- package/lib/middleware/error.cjs.map +1 -1
- package/lib/middleware/error.mjs +2 -32
- package/lib/middleware/error.mjs.map +1 -1
- package/lib/plugins/invalidateCachePlugin.cjs +19 -5
- package/lib/plugins/invalidateCachePlugin.cjs.map +1 -1
- package/lib/plugins/invalidateCachePlugin.d.ts +7 -4
- package/lib/plugins/invalidateCachePlugin.mjs +19 -5
- package/lib/plugins/invalidateCachePlugin.mjs.map +1 -1
- package/lib/servers/ExpressApp.cjs +0 -3
- package/lib/servers/ExpressApp.cjs.map +1 -1
- package/lib/servers/ExpressApp.mjs +0 -3
- package/lib/servers/ExpressApp.mjs.map +1 -1
- package/lib/servers/GraphqlServer.cjs +56 -18
- package/lib/servers/GraphqlServer.cjs.map +1 -1
- package/lib/servers/GraphqlServer.d.ts +7 -1
- package/lib/servers/GraphqlServer.mjs +56 -18
- package/lib/servers/GraphqlServer.mjs.map +1 -1
- package/lib/servers/GraphqlWs.cjs +4 -2
- package/lib/servers/GraphqlWs.cjs.map +1 -1
- package/lib/servers/GraphqlWs.mjs +4 -2
- package/lib/servers/GraphqlWs.mjs.map +1 -1
- package/package.json +11 -8
package/lib/middleware/error.mjs
CHANGED
|
@@ -1,23 +1,4 @@
|
|
|
1
|
-
import*as
|
|
2
|
-
let assetMap;
|
|
3
|
-
const stripCircular = (from, seen) => {
|
|
4
|
-
const to = Array.isArray(from) ? [] : {};
|
|
5
|
-
seen = seen || [];
|
|
6
|
-
seen.push(from);
|
|
7
|
-
Object.getOwnPropertyNames(from).forEach(key => {
|
|
8
|
-
if (!from[key] || (typeof from[key] !== 'object' && !Array.isArray(from[key]))) {
|
|
9
|
-
to[key] = from[key];
|
|
10
|
-
}
|
|
11
|
-
else if (seen.indexOf(from[key]) < 0) {
|
|
12
|
-
to[key] = stripCircular(from[key], seen.slice(0));
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
to[key] = '[Circular]';
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
const { pathname } = url.parse(config.BACKEND_URL);
|
|
1
|
+
import*as url from'url';import {config}from'../config/env-config.mjs';const { pathname } = url.parse(config.BACKEND_URL);
|
|
21
2
|
/**
|
|
22
3
|
* Middleware function that takes 4 arguments is classified as "error handling middleware"
|
|
23
4
|
* and will only get called if an error occurs.
|
|
@@ -32,17 +13,6 @@ const errorMiddleware = (e, req, res, next) => {
|
|
|
32
13
|
res.status(200).send(`[{"data": {}, "errors":[{"message": "${stack}"}]}]`);
|
|
33
14
|
}
|
|
34
15
|
else {
|
|
35
|
-
logger.error(e);
|
|
36
|
-
if (config.isDev || !assetMap) {
|
|
37
|
-
assetMap = JSON.parse(fs.readFileSync(path.join(__FRONTEND_BUILD_DIR__, 'assets.json')).toString());
|
|
38
|
-
}
|
|
39
|
-
const serverErrorScript = `<script charset="UTF-8">window.__SERVER_ERROR__=${JSON.stringify(stripCircular(e))};</script>`;
|
|
40
|
-
const vendorScript = assetMap['vendor.js']
|
|
41
|
-
? `<script src="/${assetMap['vendor.js']}" charSet="utf-8"></script>`
|
|
42
|
-
: '';
|
|
43
|
-
res.status(200).send(`<html>${serverErrorScript}<body><div id="content"></div>
|
|
44
|
-
${vendorScript}
|
|
45
|
-
<script src="/${assetMap['index.js']}" charSet="utf-8"></script>
|
|
46
|
-
</body></html>`);
|
|
16
|
+
req.logger.error(e);
|
|
47
17
|
}
|
|
48
18
|
};export{errorMiddleware};//# sourceMappingURL=error.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.mjs","sources":["../../src/middleware/error.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"error.mjs","sources":["../../src/middleware/error.ts"],"sourcesContent":[null],"names":[],"mappings":"sEAGA,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAEnD;;;;;;;AAOG;AACI,MAAM,eAAe,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,KAAI;AACjD,IAAA,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE;AACvB,QAAA,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AACzD,QAAA,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAwC,qCAAA,EAAA,KAAK,CAAO,KAAA,CAAA,CAAC,CAAC;KAC9E;SAAM;AACH,QAAA,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KACvB;AACL"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
'use strict';const invalidateCachePlugin = ({ cache }) => ({
|
|
1
|
+
'use strict';var envConfig=require('../config/env-config.cjs');const invalidateCachePlugin = ({ cache: redisClient, invalidateCacheKeyGenerator, }) => ({
|
|
2
2
|
requestDidStart(requestContext) {
|
|
3
3
|
return {
|
|
4
|
-
async
|
|
4
|
+
willSendResponse: async (responseContext) => {
|
|
5
|
+
// in case of websocket request initially the requestContext comes empty
|
|
6
|
+
if (!requestContext) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
5
9
|
try {
|
|
6
10
|
const hasErrors = !!requestContext.errors?.length;
|
|
7
11
|
const { queriesToInvalidate } = requestContext.contextValue;
|
|
@@ -11,10 +15,20 @@
|
|
|
11
15
|
return;
|
|
12
16
|
}
|
|
13
17
|
// this to get the
|
|
14
|
-
const
|
|
15
|
-
|
|
18
|
+
const nestedKeys = await Promise.all(queriesToInvalidate.map(async (query) => {
|
|
19
|
+
let defaultKey = `${envConfig.config.APP_NAME}:${query}:*`;
|
|
20
|
+
if (typeof invalidateCacheKeyGenerator === 'function') {
|
|
21
|
+
const generatedKey = invalidateCacheKeyGenerator(requestContext, responseContext, defaultKey);
|
|
22
|
+
if (generatedKey) {
|
|
23
|
+
defaultKey = generatedKey;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return redisClient.keys(defaultKey);
|
|
27
|
+
}));
|
|
16
28
|
const keys = nestedKeys.flat();
|
|
17
|
-
|
|
29
|
+
if (keys?.length) {
|
|
30
|
+
await redisClient.del(keys);
|
|
31
|
+
}
|
|
18
32
|
}
|
|
19
33
|
catch (e) {
|
|
20
34
|
requestContext.logger.error('Error occurred in invalidateCachePlugin');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invalidateCachePlugin.cjs","sources":["../../src/plugins/invalidateCachePlugin.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"invalidateCachePlugin.cjs","sources":["../../src/plugins/invalidateCachePlugin.ts"],"sourcesContent":[null],"names":["config"],"mappings":"+DAWO,MAAM,qBAAqB,GAAG,CAAC,EAClC,KAAK,EAAE,WAAW,EAClB,2BAA2B,GAI9B,MACI;AACG,IAAA,eAAe,CAAC,cAA8C,EAAA;QAC1D,OAAO;AACH,YAAA,gBAAgB,EAAE,OAAO,eAA+D,KAAI;;gBAExF,IAAI,CAAC,cAAc,EAAE;oBACjB,OAAO;iBACV;AACD,gBAAA,IAAI;oBACA,MAAM,SAAS,GAAG,CAAC,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC;AAClD,oBAAA,MAAM,EAAE,mBAAmB,EAAE,GAAG,cAAc,CAAC,YAE9C,CAAC;oBACF,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,GAAG,eAAe,CAAC,QAAQ,CAAC,WAAwC,CAAC;AAC1F,oBAAA,MAAM,UAAU,GAAG,SAAS,KAAK,UAAU,CAAC;oBAC5C,IAAI,SAAS,IAAI,CAAC,mBAAmB,EAAE,MAAM,IAAI,CAAC,UAAU,EAAE;wBAC1D,OAAO;qBACV;;AAED,oBAAA,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,GAAG,CAChC,mBAAmB,CAAC,GAAG,CAAC,OAAO,KAAa,KAAI;wBAC5C,IAAI,UAAU,GAAG,CAAG,EAAAA,gBAAM,CAAC,QAAQ,CAAA,CAAA,EAAI,KAAK,CAAA,EAAA,CAAI,CAAC;AACjD,wBAAA,IAAI,OAAO,2BAA2B,KAAK,UAAU,EAAE;4BACnD,MAAM,YAAY,GAAG,2BAA2B,CAC5C,cAAc,EACd,eAAe,EACf,UAAU,CACb,CAAC;4BACF,IAAI,YAAY,EAAE;gCACd,UAAU,GAAG,YAAY,CAAC;6BAC7B;yBACJ;AACD,wBAAA,OAAO,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;qBACvC,CAAC,CACL,CAAC;AACF,oBAAA,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;AAC/B,oBAAA,IAAI,IAAI,EAAE,MAAM,EAAE;AACd,wBAAA,MAAM,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;qBAC/B;iBACJ;gBAAC,OAAO,CAAC,EAAE;AACR,oBAAA,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;AACvE,oBAAA,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;iBAClC;aACJ;SACJ,CAAC;KACL;AACJ,CAAA"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { BaseContext } from '@apollo/server
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Redis, Cluster } from 'ioredis';
|
|
2
|
+
import type { BaseContext, GraphQLRequestContextWillSendResponse } from '@apollo/server';
|
|
3
|
+
import { ApolloServerOptions, GraphQLRequestContext } from '@apollo/server';
|
|
4
|
+
export type InvalidationKeyGenerator = (requestContext: GraphQLRequestContext<unknown>, responseContext: GraphQLRequestContextWillSendResponse<unknown>, cacheKey?: string) => string;
|
|
5
|
+
export declare const invalidateCachePlugin: ({ cache: redisClient, invalidateCacheKeyGenerator, }: {
|
|
6
|
+
cache: Redis | Cluster;
|
|
7
|
+
invalidateCacheKeyGenerator: InvalidationKeyGenerator;
|
|
5
8
|
}) => ApolloServerOptions<BaseContext>["plugins"][0];
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
const invalidateCachePlugin = ({ cache }) => ({
|
|
1
|
+
import {config}from'../config/env-config.mjs';const invalidateCachePlugin = ({ cache: redisClient, invalidateCacheKeyGenerator, }) => ({
|
|
2
2
|
requestDidStart(requestContext) {
|
|
3
3
|
return {
|
|
4
|
-
async
|
|
4
|
+
willSendResponse: async (responseContext) => {
|
|
5
|
+
// in case of websocket request initially the requestContext comes empty
|
|
6
|
+
if (!requestContext) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
5
9
|
try {
|
|
6
10
|
const hasErrors = !!requestContext.errors?.length;
|
|
7
11
|
const { queriesToInvalidate } = requestContext.contextValue;
|
|
@@ -11,10 +15,20 @@ const invalidateCachePlugin = ({ cache }) => ({
|
|
|
11
15
|
return;
|
|
12
16
|
}
|
|
13
17
|
// this to get the
|
|
14
|
-
const
|
|
15
|
-
|
|
18
|
+
const nestedKeys = await Promise.all(queriesToInvalidate.map(async (query) => {
|
|
19
|
+
let defaultKey = `${config.APP_NAME}:${query}:*`;
|
|
20
|
+
if (typeof invalidateCacheKeyGenerator === 'function') {
|
|
21
|
+
const generatedKey = invalidateCacheKeyGenerator(requestContext, responseContext, defaultKey);
|
|
22
|
+
if (generatedKey) {
|
|
23
|
+
defaultKey = generatedKey;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return redisClient.keys(defaultKey);
|
|
27
|
+
}));
|
|
16
28
|
const keys = nestedKeys.flat();
|
|
17
|
-
|
|
29
|
+
if (keys?.length) {
|
|
30
|
+
await redisClient.del(keys);
|
|
31
|
+
}
|
|
18
32
|
}
|
|
19
33
|
catch (e) {
|
|
20
34
|
requestContext.logger.error('Error occurred in invalidateCachePlugin');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invalidateCachePlugin.mjs","sources":["../../src/plugins/invalidateCachePlugin.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"invalidateCachePlugin.mjs","sources":["../../src/plugins/invalidateCachePlugin.ts"],"sourcesContent":[null],"names":[],"mappings":"8CAWO,MAAM,qBAAqB,GAAG,CAAC,EAClC,KAAK,EAAE,WAAW,EAClB,2BAA2B,GAI9B,MACI;AACG,IAAA,eAAe,CAAC,cAA8C,EAAA;QAC1D,OAAO;AACH,YAAA,gBAAgB,EAAE,OAAO,eAA+D,KAAI;;gBAExF,IAAI,CAAC,cAAc,EAAE;oBACjB,OAAO;iBACV;AACD,gBAAA,IAAI;oBACA,MAAM,SAAS,GAAG,CAAC,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC;AAClD,oBAAA,MAAM,EAAE,mBAAmB,EAAE,GAAG,cAAc,CAAC,YAE9C,CAAC;oBACF,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,GAAG,eAAe,CAAC,QAAQ,CAAC,WAAwC,CAAC;AAC1F,oBAAA,MAAM,UAAU,GAAG,SAAS,KAAK,UAAU,CAAC;oBAC5C,IAAI,SAAS,IAAI,CAAC,mBAAmB,EAAE,MAAM,IAAI,CAAC,UAAU,EAAE;wBAC1D,OAAO;qBACV;;AAED,oBAAA,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,GAAG,CAChC,mBAAmB,CAAC,GAAG,CAAC,OAAO,KAAa,KAAI;wBAC5C,IAAI,UAAU,GAAG,CAAG,EAAA,MAAM,CAAC,QAAQ,CAAA,CAAA,EAAI,KAAK,CAAA,EAAA,CAAI,CAAC;AACjD,wBAAA,IAAI,OAAO,2BAA2B,KAAK,UAAU,EAAE;4BACnD,MAAM,YAAY,GAAG,2BAA2B,CAC5C,cAAc,EACd,eAAe,EACf,UAAU,CACb,CAAC;4BACF,IAAI,YAAY,EAAE;gCACd,UAAU,GAAG,YAAY,CAAC;6BAC7B;yBACJ;AACD,wBAAA,OAAO,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;qBACvC,CAAC,CACL,CAAC;AACF,oBAAA,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;AAC/B,oBAAA,IAAI,IAAI,EAAE,MAAM,EAAE;AACd,wBAAA,MAAM,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;qBAC/B;iBACJ;gBAAC,OAAO,CAAC,EAAE;AACR,oBAAA,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;AACvE,oBAAA,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;iBAClC;aACJ;SACJ,CAAC;KACL;AACJ,CAAA"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
'use strict';var express=require('express'),bodyParser=require('body-parser'),error=require('../middleware/error.cjs'),services=require('../middleware/services.cjs'),sentry=require('../middleware/sentry.cjs'),cors=require('../middleware/cors.cjs');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 bodyParser__namespace=/*#__PURE__*/_interopNamespaceDefault(bodyParser);/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
-
const cookiesMiddleware = require('universal-cookie-express');
|
|
3
2
|
function expressApp(modules, options, middlewares, http) {
|
|
4
3
|
const app = express();
|
|
5
4
|
for (const applyBeforeware of modules.beforewares) {
|
|
6
5
|
applyBeforeware(app);
|
|
7
6
|
}
|
|
8
|
-
app.use(cookiesMiddleware());
|
|
9
7
|
app.use(services.contextServicesMiddleware(options.createContext, options.serviceContext));
|
|
10
8
|
// Don't rate limit heroku
|
|
11
9
|
app.enable('trust proxy');
|
|
@@ -13,7 +11,6 @@ function expressApp(modules, options, middlewares, http) {
|
|
|
13
11
|
if (middlewares !== null) {
|
|
14
12
|
app.use(middlewares);
|
|
15
13
|
}
|
|
16
|
-
app.use('/', express.static(__FRONTEND_BUILD_DIR__, { maxAge: '180 days' }));
|
|
17
14
|
app.use(cors.corsMiddleware);
|
|
18
15
|
app.use((req, res, next) => {
|
|
19
16
|
res.header('Access-Control-Allow-Credentials', JSON.stringify(true));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpressApp.cjs","sources":["../../src/servers/ExpressApp.ts"],"sourcesContent":[null],"names":["contextServicesMiddleware","sentryMiddleware","corsMiddleware","bodyParser","errorMiddleware","sentryErrorHandlerMiddleware"],"mappings":"kmBAAA;
|
|
1
|
+
{"version":3,"file":"ExpressApp.cjs","sources":["../../src/servers/ExpressApp.ts"],"sourcesContent":[null],"names":["contextServicesMiddleware","sentryMiddleware","corsMiddleware","bodyParser","errorMiddleware","sentryErrorHandlerMiddleware"],"mappings":"kmBAAA;AAUM,SAAU,UAAU,CAAC,OAAgB,EAAE,OAAuB,EAAE,WAAW,EAAE,IAAK,EAAA;AACpF,IAAA,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;AAEtB,IAAA,KAAK,MAAM,eAAe,IAAI,OAAO,CAAC,WAAW,EAAE;QAC/C,eAAe,CAAC,GAAG,CAAC,CAAC;KACxB;AACD,IAAA,GAAG,CAAC,GAAG,CAACA,kCAAyB,CAAC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC;;AAGlF,IAAA,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;AAE1B,IAAA,GAAG,CAAC,GAAG,CAACC,uBAAgB,CAAC,CAAC;AAE1B,IAAA,IAAI,WAAW,KAAK,IAAI,EAAE;AACtB,QAAA,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;KACxB;AAED,IAAA,GAAG,CAAC,GAAG,CAACC,mBAAc,CAAC,CAAC;IACxB,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,KAAI;AACvB,QAAA,GAAG,CAAC,MAAM,CAAC,kCAAkC,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;AACrE,QAAA,GAAG,CAAC,MAAM,CAAC,8BAA8B,EAAE,qBAAqB,CAAC,CAAC;AAClE,QAAA,GAAG,CAAC,MAAM,CACN,8BAA8B,EAC9B,6EAA6E,CAChF,CAAC;AACF,QAAA,IAAI,EAAE,CAAC;AACX,KAAC,CAAC,CAAC;AAEH,IAAA,GAAG,CAAC,GAAG,CACHC,qBAAU,CAAC,IAAI,CAAC;AACZ,QAAA,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,KAAI;;AAErB,YAAA,GAAW,CAAC,OAAO,GAAG,GAAG,CAAC;SAC9B;AACJ,KAAA,CAAC,CACL,CAAC;IACF,GAAG,CAAC,GAAG,CAACA,qBAAU,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;AAEzF,IAAA,KAAK,MAAM,eAAe,IAAI,OAAO,CAAC,WAAW,EAAE;QAC/C,eAAe,CAAC,GAAG,CAAC,CAAC;KACxB;IAED,IAAI,OAAO,EAAE;AACT,QAAA,GAAG,CAAC,GAAG,CAACC,qBAAe,CAAC,CAAC;KAC5B;AAED,IAAA,GAAG,CAAC,GAAG,CAACC,mCAA4B,CAAC,CAAC;AAEtC,IAAA,OAAO,GAAG,CAAC;AACf"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import express from'express';import*as bodyParser from'body-parser';import {errorMiddleware}from'../middleware/error.mjs';import {contextServicesMiddleware}from'../middleware/services.mjs';import {sentryMiddleware,sentryErrorHandlerMiddleware}from'../middleware/sentry.mjs';import {corsMiddleware}from'../middleware/cors.mjs';/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
-
const cookiesMiddleware = require('universal-cookie-express');
|
|
3
2
|
function expressApp(modules, options, middlewares, http) {
|
|
4
3
|
const app = express();
|
|
5
4
|
for (const applyBeforeware of modules.beforewares) {
|
|
6
5
|
applyBeforeware(app);
|
|
7
6
|
}
|
|
8
|
-
app.use(cookiesMiddleware());
|
|
9
7
|
app.use(contextServicesMiddleware(options.createContext, options.serviceContext));
|
|
10
8
|
// Don't rate limit heroku
|
|
11
9
|
app.enable('trust proxy');
|
|
@@ -13,7 +11,6 @@ function expressApp(modules, options, middlewares, http) {
|
|
|
13
11
|
if (middlewares !== null) {
|
|
14
12
|
app.use(middlewares);
|
|
15
13
|
}
|
|
16
|
-
app.use('/', express.static(__FRONTEND_BUILD_DIR__, { maxAge: '180 days' }));
|
|
17
14
|
app.use(corsMiddleware);
|
|
18
15
|
app.use((req, res, next) => {
|
|
19
16
|
res.header('Access-Control-Allow-Credentials', JSON.stringify(true));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpressApp.mjs","sources":["../../src/servers/ExpressApp.ts"],"sourcesContent":[null],"names":[],"mappings":"sUAAA;
|
|
1
|
+
{"version":3,"file":"ExpressApp.mjs","sources":["../../src/servers/ExpressApp.ts"],"sourcesContent":[null],"names":[],"mappings":"sUAAA;AAUM,SAAU,UAAU,CAAC,OAAgB,EAAE,OAAuB,EAAE,WAAW,EAAE,IAAK,EAAA;AACpF,IAAA,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;AAEtB,IAAA,KAAK,MAAM,eAAe,IAAI,OAAO,CAAC,WAAW,EAAE;QAC/C,eAAe,CAAC,GAAG,CAAC,CAAC;KACxB;AACD,IAAA,GAAG,CAAC,GAAG,CAAC,yBAAyB,CAAC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC;;AAGlF,IAAA,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;AAE1B,I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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
'use strict';var server=require('@apollo/server'),
|
|
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'),cachePlugin=require('@apollo/server-plugin-response-cache');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'),_=require('lodash-es'),invalidateCachePlugin=require('../plugins/invalidateCachePlugin.cjs'),GraphqlWs=require('./GraphqlWs.cjs'),envConfig=require('../config/env-config.cjs');const responseCachePlugin = cachePlugin.default ?? cachePlugin;
|
|
2
2
|
if ((process.env.LOG_LEVEL && process.env.LOG_LEVEL === 'trace') || process.env.LOG_LEVEL === 'debug') ;
|
|
3
3
|
// @workaround as the `dataSources` not available in Subscription (websocket) Context.
|
|
4
4
|
// https://github.com/apollographql/apollo-server/issues/1526 need to revisit in Apollo-Server v3.
|
|
@@ -11,32 +11,36 @@ const constructDataSourcesForSubscriptions = (context, cache, dataSources) => {
|
|
|
11
11
|
}
|
|
12
12
|
return dataSources;
|
|
13
13
|
};
|
|
14
|
-
let wsServerCleanup;
|
|
15
14
|
class GraphqlServer {
|
|
16
15
|
app;
|
|
17
16
|
httpServer;
|
|
18
17
|
redisClient;
|
|
19
18
|
moduleService;
|
|
20
19
|
enableSubscription;
|
|
20
|
+
cacheKeyGenerator;
|
|
21
|
+
invalidateCacheKeyGenerator;
|
|
21
22
|
logger;
|
|
22
|
-
|
|
23
|
+
graphqlWsServer;
|
|
24
|
+
constructor(app, httpServer, redisClient, moduleService, enableSubscription = true, cacheKeyGenerator, invalidateCacheKeyGenerator) {
|
|
23
25
|
this.app = app;
|
|
24
26
|
this.httpServer = httpServer;
|
|
25
27
|
this.redisClient = redisClient;
|
|
26
28
|
this.moduleService = moduleService;
|
|
27
29
|
this.enableSubscription = enableSubscription;
|
|
30
|
+
this.cacheKeyGenerator = cacheKeyGenerator;
|
|
31
|
+
this.invalidateCacheKeyGenerator = invalidateCacheKeyGenerator;
|
|
28
32
|
this.logger = this.moduleService.logger.child({ className: 'GraphqlServer' });
|
|
29
33
|
if (enableSubscription) {
|
|
30
34
|
const wsServer = new ws.WebSocketServer({
|
|
31
35
|
server: this.httpServer,
|
|
32
36
|
path: envConfig.config.GRAPHQL_ENDPOINT,
|
|
33
37
|
});
|
|
34
|
-
new GraphqlWs.GraphqlWs(wsServer, this.moduleService, this.redisClient);
|
|
35
|
-
wsServerCleanup = ws$1.useServer({ schema: this.moduleService.schema }, wsServer);
|
|
38
|
+
this.graphqlWsServer = new GraphqlWs.GraphqlWs(wsServer, this.moduleService, this.redisClient);
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
async initialize() {
|
|
39
42
|
this.logger.info('GraphqlServer initializing...');
|
|
43
|
+
this.graphqlWsServer.create();
|
|
40
44
|
const apolloServer = this.configureApolloServer();
|
|
41
45
|
await apolloServer.start();
|
|
42
46
|
const corsOptions = {
|
|
@@ -74,7 +78,7 @@ class GraphqlServer {
|
|
|
74
78
|
context.userIp = this.getUserIpAddress(req);
|
|
75
79
|
}
|
|
76
80
|
catch (err) {
|
|
77
|
-
this.logger.error('adding context to graphql failed due to [%
|
|
81
|
+
this.logger.error(err, 'adding context to graphql failed due to [%s]', err.message);
|
|
78
82
|
throw err;
|
|
79
83
|
}
|
|
80
84
|
return {
|
|
@@ -99,34 +103,68 @@ class GraphqlServer {
|
|
|
99
103
|
return ip;
|
|
100
104
|
}
|
|
101
105
|
configureApolloServer() {
|
|
106
|
+
const redisStore = new KeyvRedis(this.redisClient);
|
|
107
|
+
redisStore.on('error', (err) => {
|
|
108
|
+
this.logger.error(err, 'Redis connection error:');
|
|
109
|
+
});
|
|
110
|
+
const keyvCache = new Keyv({ store: redisStore, namespace: envConfig.config.APP_NAME });
|
|
111
|
+
const isCacheable = (requestContext) => {
|
|
112
|
+
const cache = requestContext.contextValue.overallCachePolicy;
|
|
113
|
+
if (!cache)
|
|
114
|
+
return false;
|
|
115
|
+
// eslint-disable-next-line no-param-reassign
|
|
116
|
+
requestContext.overallCachePolicy.maxAge = cache.maxAge;
|
|
117
|
+
return requestContext.overallCachePolicy.maxAge > 0;
|
|
118
|
+
};
|
|
119
|
+
const cacheAdapter = new utils_keyvadapter.KeyvAdapter(keyvCache);
|
|
120
|
+
const cacheGet = cacheAdapter.get.bind(cacheAdapter);
|
|
121
|
+
cacheAdapter.get = (key) => cacheGet(key.replaceAll('fqc:', ''));
|
|
122
|
+
const cacheSet = cacheAdapter.set.bind(cacheAdapter);
|
|
123
|
+
cacheAdapter.set = (key, value, opts) => cacheSet(key.replaceAll('fqc:', ''), value, opts);
|
|
124
|
+
const { cacheKeyGenerator, invalidateCacheKeyGenerator } = this;
|
|
102
125
|
const serverConfig = {
|
|
103
126
|
schema: this.moduleService.schema,
|
|
104
127
|
allowBatchedHttpRequests: true,
|
|
105
|
-
cache:
|
|
106
|
-
disableBatchReads: true,
|
|
107
|
-
}),
|
|
128
|
+
cache: cacheAdapter,
|
|
108
129
|
plugins: [
|
|
109
130
|
drainHttpServer.ApolloServerPluginDrainHttpServer({ httpServer: this.httpServer }),
|
|
110
|
-
cacheControl.ApolloServerPluginCacheControl(
|
|
111
|
-
calculateHttpHeaders: false,
|
|
112
|
-
}),
|
|
131
|
+
cacheControl.ApolloServerPluginCacheControl(),
|
|
113
132
|
responseCachePlugin({
|
|
114
|
-
sessionId: ({ contextValue }) => Promise.resolve(contextValue?.
|
|
115
|
-
generateCacheKey(
|
|
116
|
-
|
|
133
|
+
sessionId: ({ contextValue }) => Promise.resolve(contextValue?.user?.sub ?? null),
|
|
134
|
+
generateCacheKey(requestContext) {
|
|
135
|
+
const { queryHash, request } = requestContext;
|
|
136
|
+
const [, queryName] = request.query?.match(/{\s*(\w+)/) ?? [];
|
|
137
|
+
const cacheKey = `${queryName}:${queryHash}`;
|
|
138
|
+
try {
|
|
139
|
+
if (typeof cacheKeyGenerator === 'function') {
|
|
140
|
+
const generatedKey = cacheKeyGenerator(requestContext, cacheKey);
|
|
141
|
+
return generatedKey || cacheKey;
|
|
142
|
+
}
|
|
143
|
+
return cacheKey;
|
|
144
|
+
}
|
|
145
|
+
catch (e) {
|
|
146
|
+
// `this.logger` won't work here
|
|
147
|
+
console.warn('GenerateCacheKey Failed %s', e.message);
|
|
148
|
+
return cacheKey;
|
|
149
|
+
}
|
|
117
150
|
},
|
|
151
|
+
shouldWriteToCache: (ctx) =>
|
|
152
|
+
// Cache only successful responses
|
|
153
|
+
isCacheable(ctx) && _.isEmpty(ctx?.response?.body?.singleResult.errors),
|
|
118
154
|
}),
|
|
119
|
-
invalidateCachePlugin.invalidateCachePlugin({ cache: this.redisClient }),
|
|
155
|
+
invalidateCachePlugin.invalidateCachePlugin({ cache: this.redisClient, invalidateCacheKeyGenerator }),
|
|
120
156
|
],
|
|
121
157
|
};
|
|
122
158
|
if (this.enableSubscription) {
|
|
123
159
|
serverConfig.plugins.push({
|
|
124
160
|
async serverWillStart() {
|
|
125
|
-
|
|
161
|
+
const response = {
|
|
126
162
|
async drainServer() {
|
|
127
|
-
await
|
|
163
|
+
await this?.graphqlWsServer?.disconnect();
|
|
128
164
|
},
|
|
129
165
|
};
|
|
166
|
+
response.drainServer.bind(this);
|
|
167
|
+
return response;
|
|
130
168
|
},
|
|
131
169
|
});
|
|
132
170
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GraphqlServer.cjs","sources":["../../src/servers/GraphqlServer.ts"],"sourcesContent":[null],"names":["WebSocketServer","config","GraphqlWs","
|
|
1
|
+
{"version":3,"file":"GraphqlServer.cjs","sources":["../../src/servers/GraphqlServer.ts"],"sourcesContent":[null],"names":["WebSocketServer","config","GraphqlWs","expressMiddleware","KeyvAdapter","ApolloServerPluginDrainHttpServer","ApolloServerPluginCacheControl","isEmpty","invalidateCachePlugin","ApolloServer"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
+
import { GraphQLRequestContext } from '@apollo/server';
|
|
1
2
|
import * as IORedis from 'ioredis';
|
|
2
3
|
import 'isomorphic-fetch';
|
|
3
4
|
import { Express } from 'express';
|
|
4
5
|
import * as http from 'http';
|
|
6
|
+
import { InvalidationKeyGenerator } from '../plugins';
|
|
5
7
|
import { IModuleService } from '../interfaces';
|
|
8
|
+
export type KeyGenerator = (context: GraphQLRequestContext<unknown>, cacheKey?: string) => string;
|
|
6
9
|
export declare class GraphqlServer {
|
|
7
10
|
private app;
|
|
8
11
|
private httpServer;
|
|
9
12
|
private redisClient;
|
|
10
13
|
private moduleService;
|
|
11
14
|
private enableSubscription;
|
|
15
|
+
private readonly cacheKeyGenerator?;
|
|
16
|
+
private readonly invalidateCacheKeyGenerator?;
|
|
12
17
|
private logger;
|
|
13
|
-
|
|
18
|
+
private graphqlWsServer;
|
|
19
|
+
constructor(app: Express, httpServer: http.Server, redisClient: IORedis.Redis | IORedis.Cluster, moduleService: IModuleService, enableSubscription?: boolean, cacheKeyGenerator?: KeyGenerator, invalidateCacheKeyGenerator?: InvalidationKeyGenerator);
|
|
14
20
|
initialize(): Promise<void>;
|
|
15
21
|
getUserIpAddress(req: any): any;
|
|
16
22
|
private configureApolloServer;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {ApolloServer}from'@apollo/server';import {
|
|
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 cachePlugin from'@apollo/server-plugin-response-cache';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 {isEmpty}from'lodash-es';import {invalidateCachePlugin}from'../plugins/invalidateCachePlugin.mjs';import {GraphqlWs}from'./GraphqlWs.mjs';import {config}from'../config/env-config.mjs';const responseCachePlugin = cachePlugin.default ?? cachePlugin;
|
|
2
2
|
if ((process.env.LOG_LEVEL && process.env.LOG_LEVEL === 'trace') || process.env.LOG_LEVEL === 'debug') ;
|
|
3
3
|
// @workaround as the `dataSources` not available in Subscription (websocket) Context.
|
|
4
4
|
// https://github.com/apollographql/apollo-server/issues/1526 need to revisit in Apollo-Server v3.
|
|
@@ -11,32 +11,36 @@ const constructDataSourcesForSubscriptions = (context, cache, dataSources) => {
|
|
|
11
11
|
}
|
|
12
12
|
return dataSources;
|
|
13
13
|
};
|
|
14
|
-
let wsServerCleanup;
|
|
15
14
|
class GraphqlServer {
|
|
16
15
|
app;
|
|
17
16
|
httpServer;
|
|
18
17
|
redisClient;
|
|
19
18
|
moduleService;
|
|
20
19
|
enableSubscription;
|
|
20
|
+
cacheKeyGenerator;
|
|
21
|
+
invalidateCacheKeyGenerator;
|
|
21
22
|
logger;
|
|
22
|
-
|
|
23
|
+
graphqlWsServer;
|
|
24
|
+
constructor(app, httpServer, redisClient, moduleService, enableSubscription = true, cacheKeyGenerator, invalidateCacheKeyGenerator) {
|
|
23
25
|
this.app = app;
|
|
24
26
|
this.httpServer = httpServer;
|
|
25
27
|
this.redisClient = redisClient;
|
|
26
28
|
this.moduleService = moduleService;
|
|
27
29
|
this.enableSubscription = enableSubscription;
|
|
30
|
+
this.cacheKeyGenerator = cacheKeyGenerator;
|
|
31
|
+
this.invalidateCacheKeyGenerator = invalidateCacheKeyGenerator;
|
|
28
32
|
this.logger = this.moduleService.logger.child({ className: 'GraphqlServer' });
|
|
29
33
|
if (enableSubscription) {
|
|
30
34
|
const wsServer = new WebSocketServer({
|
|
31
35
|
server: this.httpServer,
|
|
32
36
|
path: config.GRAPHQL_ENDPOINT,
|
|
33
37
|
});
|
|
34
|
-
new GraphqlWs(wsServer, this.moduleService, this.redisClient);
|
|
35
|
-
wsServerCleanup = useServer({ schema: this.moduleService.schema }, wsServer);
|
|
38
|
+
this.graphqlWsServer = new GraphqlWs(wsServer, this.moduleService, this.redisClient);
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
async initialize() {
|
|
39
42
|
this.logger.info('GraphqlServer initializing...');
|
|
43
|
+
this.graphqlWsServer.create();
|
|
40
44
|
const apolloServer = this.configureApolloServer();
|
|
41
45
|
await apolloServer.start();
|
|
42
46
|
const corsOptions = {
|
|
@@ -74,7 +78,7 @@ class GraphqlServer {
|
|
|
74
78
|
context.userIp = this.getUserIpAddress(req);
|
|
75
79
|
}
|
|
76
80
|
catch (err) {
|
|
77
|
-
this.logger.error('adding context to graphql failed due to [%
|
|
81
|
+
this.logger.error(err, 'adding context to graphql failed due to [%s]', err.message);
|
|
78
82
|
throw err;
|
|
79
83
|
}
|
|
80
84
|
return {
|
|
@@ -99,34 +103,68 @@ class GraphqlServer {
|
|
|
99
103
|
return ip;
|
|
100
104
|
}
|
|
101
105
|
configureApolloServer() {
|
|
106
|
+
const redisStore = new KeyvRedis(this.redisClient);
|
|
107
|
+
redisStore.on('error', (err) => {
|
|
108
|
+
this.logger.error(err, 'Redis connection error:');
|
|
109
|
+
});
|
|
110
|
+
const keyvCache = new Keyv({ store: redisStore, namespace: config.APP_NAME });
|
|
111
|
+
const isCacheable = (requestContext) => {
|
|
112
|
+
const cache = requestContext.contextValue.overallCachePolicy;
|
|
113
|
+
if (!cache)
|
|
114
|
+
return false;
|
|
115
|
+
// eslint-disable-next-line no-param-reassign
|
|
116
|
+
requestContext.overallCachePolicy.maxAge = cache.maxAge;
|
|
117
|
+
return requestContext.overallCachePolicy.maxAge > 0;
|
|
118
|
+
};
|
|
119
|
+
const cacheAdapter = new KeyvAdapter(keyvCache);
|
|
120
|
+
const cacheGet = cacheAdapter.get.bind(cacheAdapter);
|
|
121
|
+
cacheAdapter.get = (key) => cacheGet(key.replaceAll('fqc:', ''));
|
|
122
|
+
const cacheSet = cacheAdapter.set.bind(cacheAdapter);
|
|
123
|
+
cacheAdapter.set = (key, value, opts) => cacheSet(key.replaceAll('fqc:', ''), value, opts);
|
|
124
|
+
const { cacheKeyGenerator, invalidateCacheKeyGenerator } = this;
|
|
102
125
|
const serverConfig = {
|
|
103
126
|
schema: this.moduleService.schema,
|
|
104
127
|
allowBatchedHttpRequests: true,
|
|
105
|
-
cache:
|
|
106
|
-
disableBatchReads: true,
|
|
107
|
-
}),
|
|
128
|
+
cache: cacheAdapter,
|
|
108
129
|
plugins: [
|
|
109
130
|
ApolloServerPluginDrainHttpServer({ httpServer: this.httpServer }),
|
|
110
|
-
ApolloServerPluginCacheControl(
|
|
111
|
-
calculateHttpHeaders: false,
|
|
112
|
-
}),
|
|
131
|
+
ApolloServerPluginCacheControl(),
|
|
113
132
|
responseCachePlugin({
|
|
114
|
-
sessionId: ({ contextValue }) => Promise.resolve(contextValue?.
|
|
115
|
-
generateCacheKey(
|
|
116
|
-
|
|
133
|
+
sessionId: ({ contextValue }) => Promise.resolve(contextValue?.user?.sub ?? null),
|
|
134
|
+
generateCacheKey(requestContext) {
|
|
135
|
+
const { queryHash, request } = requestContext;
|
|
136
|
+
const [, queryName] = request.query?.match(/{\s*(\w+)/) ?? [];
|
|
137
|
+
const cacheKey = `${queryName}:${queryHash}`;
|
|
138
|
+
try {
|
|
139
|
+
if (typeof cacheKeyGenerator === 'function') {
|
|
140
|
+
const generatedKey = cacheKeyGenerator(requestContext, cacheKey);
|
|
141
|
+
return generatedKey || cacheKey;
|
|
142
|
+
}
|
|
143
|
+
return cacheKey;
|
|
144
|
+
}
|
|
145
|
+
catch (e) {
|
|
146
|
+
// `this.logger` won't work here
|
|
147
|
+
console.warn('GenerateCacheKey Failed %s', e.message);
|
|
148
|
+
return cacheKey;
|
|
149
|
+
}
|
|
117
150
|
},
|
|
151
|
+
shouldWriteToCache: (ctx) =>
|
|
152
|
+
// Cache only successful responses
|
|
153
|
+
isCacheable(ctx) && isEmpty(ctx?.response?.body?.singleResult.errors),
|
|
118
154
|
}),
|
|
119
|
-
invalidateCachePlugin({ cache: this.redisClient }),
|
|
155
|
+
invalidateCachePlugin({ cache: this.redisClient, invalidateCacheKeyGenerator }),
|
|
120
156
|
],
|
|
121
157
|
};
|
|
122
158
|
if (this.enableSubscription) {
|
|
123
159
|
serverConfig.plugins.push({
|
|
124
160
|
async serverWillStart() {
|
|
125
|
-
|
|
161
|
+
const response = {
|
|
126
162
|
async drainServer() {
|
|
127
|
-
await
|
|
163
|
+
await this?.graphqlWsServer?.disconnect();
|
|
128
164
|
},
|
|
129
165
|
};
|
|
166
|
+
response.drainServer.bind(this);
|
|
167
|
+
return response;
|
|
130
168
|
},
|
|
131
169
|
});
|
|
132
170
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GraphqlServer.mjs","sources":["../../src/servers/GraphqlServer.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GraphqlServer.mjs","sources":["../../src/servers/GraphqlServer.ts"],"sourcesContent":[null],"names":[],"mappings":"iuBA6BA,MAAM,mBAAmB,GAAI,WAAmB,CAAC,OAAO,IAAI,WAAW,CAAC;AAGxE,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,C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2BAA2B,EAAE,CAAC;AAClF,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"}
|
|
@@ -6,8 +6,9 @@ const constructDataSourcesForSubscriptions = (context, cache, dataSources) => {
|
|
|
6
6
|
};
|
|
7
7
|
// tslint:disable-next-line:forin
|
|
8
8
|
for (const prop in dataSources) {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
if (dataSources[prop] && typeof dataSources[prop]?.initialize === 'function') {
|
|
10
|
+
intializeDataSource(dataSources[prop]);
|
|
11
|
+
}
|
|
11
12
|
}
|
|
12
13
|
return dataSources;
|
|
13
14
|
};
|
|
@@ -21,6 +22,7 @@ class GraphqlWs {
|
|
|
21
22
|
this.wsServer = wsServer;
|
|
22
23
|
this.moduleService = moduleService;
|
|
23
24
|
this.cache = cache;
|
|
25
|
+
this.logger = this.moduleService.logger;
|
|
24
26
|
}
|
|
25
27
|
create() {
|
|
26
28
|
this.subscriptionServer = ws.useServer({
|