@common-stack/server-stack 7.2.1-alpha.71 → 7.2.1-alpha.74
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/servers/GraphqlWs.cjs +3 -44
- package/lib/servers/GraphqlWs.cjs.map +1 -1
- package/lib/servers/GraphqlWs.mjs +3 -44
- package/lib/servers/GraphqlWs.mjs.map +1 -1
- package/lib/servers/WebsocketMultipathUpdate.cjs +4 -2
- package/lib/servers/WebsocketMultipathUpdate.cjs.map +1 -1
- package/lib/servers/WebsocketMultipathUpdate.mjs +4 -2
- package/lib/servers/WebsocketMultipathUpdate.mjs.map +1 -1
- package/lib/servers/websocket-context.cjs +70 -0
- package/lib/servers/websocket-context.cjs.map +1 -0
- package/lib/servers/websocket-context.d.ts +30 -0
- package/lib/servers/websocket-context.mjs +70 -0
- package/lib/servers/websocket-context.mjs.map +1 -0
- package/package.json +4 -4
|
@@ -1,18 +1,4 @@
|
|
|
1
|
-
'use strict';var ws=require('graphql-ws/lib/use/ws');require('graphql')
|
|
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 {
|
|
1
|
+
'use strict';var ws=require('graphql-ws/lib/use/ws');require('graphql');var websocketContext=require('./websocket-context.cjs');class GraphqlWs {
|
|
16
2
|
wsServer;
|
|
17
3
|
moduleService;
|
|
18
4
|
cache;
|
|
@@ -28,35 +14,8 @@ class GraphqlWs {
|
|
|
28
14
|
this.subscriptionServer = ws.useServer({
|
|
29
15
|
schema: this.moduleService.schema,
|
|
30
16
|
// Adding a context property lets you add data to your GraphQL operation context
|
|
31
|
-
context
|
|
32
|
-
|
|
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
|
-
},
|
|
17
|
+
// Using shared context creation function to maintain consistency
|
|
18
|
+
context: async (ctx) => websocketContext.createWebSocketContext(ctx, this.moduleService, this.cache),
|
|
60
19
|
// onConnect: async (ctx) => {
|
|
61
20
|
// // do anything when connected
|
|
62
21
|
// },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GraphqlWs.cjs","sources":["../../src/servers/GraphqlWs.ts"],"sourcesContent":[null],"names":["useServer"],"mappings":"
|
|
1
|
+
{"version":3,"file":"GraphqlWs.cjs","sources":["../../src/servers/GraphqlWs.ts"],"sourcesContent":[null],"names":["useServer","createWebSocketContext"],"mappings":"sIAmDa,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;QAEhD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC;KAC3C;IAEM,MAAM,GAAA;AACT,QAAA,IAAI,CAAC,kBAAkB,GAAGA,YAAS,CAC/B;AACI,YAAA,MAAM,EAAE,IAAI,CAAC,aAAa,CAAC,MAAM;;;AAGjC,YAAA,OAAO,EAAE,OAAO,GAAG,KAAKC,uCAAsB,CAAC,GAAG,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCtF,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,18 +1,4 @@
|
|
|
1
|
-
import {useServer}from'graphql-ws/lib/use/ws';import'graphql'
|
|
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 {
|
|
1
|
+
import {useServer}from'graphql-ws/lib/use/ws';import'graphql';import {createWebSocketContext}from'./websocket-context.mjs';class GraphqlWs {
|
|
16
2
|
wsServer;
|
|
17
3
|
moduleService;
|
|
18
4
|
cache;
|
|
@@ -28,35 +14,8 @@ class GraphqlWs {
|
|
|
28
14
|
this.subscriptionServer = useServer({
|
|
29
15
|
schema: this.moduleService.schema,
|
|
30
16
|
// Adding a context property lets you add data to your GraphQL operation context
|
|
31
|
-
context
|
|
32
|
-
|
|
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
|
-
},
|
|
17
|
+
// Using shared context creation function to maintain consistency
|
|
18
|
+
context: async (ctx) => createWebSocketContext(ctx, this.moduleService, this.cache),
|
|
60
19
|
// onConnect: async (ctx) => {
|
|
61
20
|
// // do anything when connected
|
|
62
21
|
// },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GraphqlWs.mjs","sources":["../../src/servers/GraphqlWs.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GraphqlWs.mjs","sources":["../../src/servers/GraphqlWs.ts"],"sourcesContent":[null],"names":[],"mappings":"iIAmDa,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;QAEhD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC;KAC3C;IAEM,MAAM,GAAA;AACT,QAAA,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAC/B;AACI,YAAA,MAAM,EAAE,IAAI,CAAC,aAAa,CAAC,MAAM;;;AAGjC,YAAA,OAAO,EAAE,OAAO,GAAG,KAAK,sBAAsB,CAAC,GAAG,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCtF,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,4 +1,4 @@
|
|
|
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 {
|
|
1
|
+
'use strict';var url=require('url'),ws=require('ws'),ws$1=require('graphql-ws/lib/use/ws'),websocketContext=require('./websocket-context.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 url__namespace=/*#__PURE__*/_interopNamespaceDefault(url);class WebsocketMultiPathServer {
|
|
2
2
|
moduleService;
|
|
3
3
|
cache;
|
|
4
4
|
webSockets = {};
|
|
@@ -9,10 +9,12 @@
|
|
|
9
9
|
this.cache = cache;
|
|
10
10
|
this._graphqlWs = new ws.WebSocketServer({ noServer: true, path: __GRAPHQL_ENDPOINT__ });
|
|
11
11
|
this.webSockets[__GRAPHQL_ENDPOINT__] = this._graphqlWs;
|
|
12
|
-
this.webSockets[__GRAPHQL_ENDPOINT__].on('connection', (
|
|
12
|
+
this.webSockets[__GRAPHQL_ENDPOINT__].on('connection', () => {
|
|
13
13
|
console.log('--REQUESTED CONNECTION--', this._graphqlWs);
|
|
14
14
|
ws$1.useServer({
|
|
15
15
|
schema: moduleService.schema,
|
|
16
|
+
// Using shared context creation function to maintain consistency with GraphqlWs
|
|
17
|
+
context: async (ctx) => websocketContext.createWebSocketContext(ctx, moduleService, cache),
|
|
16
18
|
}, this._graphqlWs);
|
|
17
19
|
});
|
|
18
20
|
for (let key in multiplePathConfig) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebsocketMultipathUpdate.cjs","sources":["../../src/servers/WebsocketMultipathUpdate.ts"],"sourcesContent":[null],"names":["WebSocketServer","useServer","url"],"mappings":"
|
|
1
|
+
{"version":3,"file":"WebsocketMultipathUpdate.cjs","sources":["../../src/servers/WebsocketMultipathUpdate.ts"],"sourcesContent":[null],"names":["WebSocketServer","useServer","createWebSocketContext","url"],"mappings":"ifAea,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;QACxD,IAAI,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC,EAAE,CAAC,YAAY,EAAE,MAAK;YACxD,OAAO,CAAC,GAAG,CAAC,0BAA0B,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;AACzD,YAAAC,cAAS,CACL;gBACI,MAAM,EAAE,aAAa,CAAC,MAAM;;AAE5B,gBAAA,OAAO,EAAE,OAAO,GAAG,KAAKC,uCAAsB,CAAC,GAAG,EAAE,aAAa,EAAE,KAAK,CAAC;AAC5E,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;gBACz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,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,4 +1,4 @@
|
|
|
1
|
-
import*as url from'url';import {WebSocketServer}from'ws';import {useServer}from'graphql-ws/lib/use/ws';class WebsocketMultiPathServer {
|
|
1
|
+
import*as url from'url';import {WebSocketServer}from'ws';import {useServer}from'graphql-ws/lib/use/ws';import {createWebSocketContext}from'./websocket-context.mjs';class WebsocketMultiPathServer {
|
|
2
2
|
moduleService;
|
|
3
3
|
cache;
|
|
4
4
|
webSockets = {};
|
|
@@ -9,10 +9,12 @@ import*as url from'url';import {WebSocketServer}from'ws';import {useServer}from'
|
|
|
9
9
|
this.cache = cache;
|
|
10
10
|
this._graphqlWs = new WebSocketServer({ noServer: true, path: __GRAPHQL_ENDPOINT__ });
|
|
11
11
|
this.webSockets[__GRAPHQL_ENDPOINT__] = this._graphqlWs;
|
|
12
|
-
this.webSockets[__GRAPHQL_ENDPOINT__].on('connection', (
|
|
12
|
+
this.webSockets[__GRAPHQL_ENDPOINT__].on('connection', () => {
|
|
13
13
|
console.log('--REQUESTED CONNECTION--', this._graphqlWs);
|
|
14
14
|
useServer({
|
|
15
15
|
schema: moduleService.schema,
|
|
16
|
+
// Using shared context creation function to maintain consistency with GraphqlWs
|
|
17
|
+
context: async (ctx) => createWebSocketContext(ctx, moduleService, cache),
|
|
16
18
|
}, this._graphqlWs);
|
|
17
19
|
});
|
|
18
20
|
for (let key in multiplePathConfig) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebsocketMultipathUpdate.mjs","sources":["../../src/servers/WebsocketMultipathUpdate.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"WebsocketMultipathUpdate.mjs","sources":["../../src/servers/WebsocketMultipathUpdate.ts"],"sourcesContent":[null],"names":[],"mappings":"0KAea,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;QACxD,IAAI,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC,EAAE,CAAC,YAAY,EAAE,MAAK;YACxD,OAAO,CAAC,GAAG,CAAC,0BAA0B,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;AACzD,YAAA,SAAS,CACL;gBACI,MAAM,EAAE,aAAa,CAAC,MAAM;;AAE5B,gBAAA,OAAO,EAAE,OAAO,GAAG,KAAK,sBAAsB,CAAC,GAAG,EAAE,aAAa,EAAE,KAAK,CAAC;AAC5E,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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AY,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"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict';/**
|
|
2
|
+
* Helper function to construct data sources for WebSocket subscriptions
|
|
3
|
+
*
|
|
4
|
+
* @workaround DataSources are an Apollo Server feature that only work with HTTP requests.
|
|
5
|
+
* When using graphql-ws for WebSocket subscriptions, we must manually initialize data sources
|
|
6
|
+
* because graphql-ws has a separate context pipeline from Apollo Server's HTTP pipeline.
|
|
7
|
+
*
|
|
8
|
+
* This is necessary as of:
|
|
9
|
+
* - Apollo Server v4.10.4
|
|
10
|
+
* - graphql-ws v5.11.2
|
|
11
|
+
*
|
|
12
|
+
* References:
|
|
13
|
+
* - Original issue: https://github.com/apollographql/apollo-server/issues/1526
|
|
14
|
+
* - Community solution: https://github.com/apollographql/apollo-server/issues/1526#issuecomment-502884432
|
|
15
|
+
* - graphql-ws context: https://github.com/enisdenjo/graphql-ws#context
|
|
16
|
+
*/
|
|
17
|
+
const constructDataSourcesForSubscriptions = (context, cache, dataSources) => {
|
|
18
|
+
const initializeDataSource = (instance) => {
|
|
19
|
+
instance.initialize({ context, cache });
|
|
20
|
+
};
|
|
21
|
+
// tslint:disable-next-line:forin
|
|
22
|
+
for (const prop in dataSources) {
|
|
23
|
+
if (dataSources[prop] && typeof dataSources[prop]?.initialize === 'function') {
|
|
24
|
+
initializeDataSource(dataSources[prop]);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return dataSources;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Creates the WebSocket subscription context
|
|
31
|
+
* This function is shared between GraphqlWs and WebsocketMultiPathServer
|
|
32
|
+
* to ensure consistent context creation across all subscription endpoints.
|
|
33
|
+
*
|
|
34
|
+
* @param ctx - The graphql-ws context containing connectionParams
|
|
35
|
+
* @param moduleService - The module service for creating context
|
|
36
|
+
* @param cache - Redis cache instance
|
|
37
|
+
* @returns Promise<object> - The complete subscription context
|
|
38
|
+
*/
|
|
39
|
+
async function createWebSocketContext(ctx, moduleService, cache) {
|
|
40
|
+
try {
|
|
41
|
+
const connectionParams = ctx.connectionParams || {};
|
|
42
|
+
const pureContext = await moduleService.createContext(connectionParams, null);
|
|
43
|
+
const contextServices = await moduleService.serviceContext(connectionParams, null);
|
|
44
|
+
const context = {
|
|
45
|
+
...contextServices,
|
|
46
|
+
...pureContext,
|
|
47
|
+
preferences: moduleService.defaultPreferences,
|
|
48
|
+
...ctx,
|
|
49
|
+
};
|
|
50
|
+
const addons = {
|
|
51
|
+
dataSources: constructDataSourcesForSubscriptions(context, cache, moduleService.dataSource),
|
|
52
|
+
};
|
|
53
|
+
return {
|
|
54
|
+
...context,
|
|
55
|
+
...addons,
|
|
56
|
+
...ctx,
|
|
57
|
+
...pureContext,
|
|
58
|
+
preferences: moduleService.defaultPreferences,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
moduleService.logger.error('Error creating WebSocket context:', err);
|
|
63
|
+
// Return a minimal context to prevent crashes
|
|
64
|
+
return {
|
|
65
|
+
userContext: {},
|
|
66
|
+
req: {},
|
|
67
|
+
connectionParams: ctx.connectionParams || {},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}exports.constructDataSourcesForSubscriptions=constructDataSourcesForSubscriptions;exports.createWebSocketContext=createWebSocketContext;//# sourceMappingURL=websocket-context.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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AAA,GAAG,OAAO;AACV,YAAA,GAAG,MAAM;AACT,YAAA,GAAG,GAAG;AACN,YAAA,GAAG,WAAW;YACd,WAAW,EAAE,aAAa,CAAC,kBAAkB;SAChD,CAAC;KACL;IAAC,OAAO,GAAG,EAAE;QACV,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,mCAAmC,EAAE,GAAG,CAAC,CAAC;;QAErE,OAAO;AACH,YAAA,WAAW,EAAE,EAAE;AACf,YAAA,GAAG,EAAE,EAAE;AACP,YAAA,gBAAgB,EAAE,GAAG,CAAC,gBAAgB,IAAI,EAAE;SAC/C,CAAC;KACL;AACL"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as IORedis from 'ioredis';
|
|
2
|
+
import { IModuleService } from '../interfaces';
|
|
3
|
+
/**
|
|
4
|
+
* Helper function to construct data sources for WebSocket subscriptions
|
|
5
|
+
*
|
|
6
|
+
* @workaround DataSources are an Apollo Server feature that only work with HTTP requests.
|
|
7
|
+
* When using graphql-ws for WebSocket subscriptions, we must manually initialize data sources
|
|
8
|
+
* because graphql-ws has a separate context pipeline from Apollo Server's HTTP pipeline.
|
|
9
|
+
*
|
|
10
|
+
* This is necessary as of:
|
|
11
|
+
* - Apollo Server v4.10.4
|
|
12
|
+
* - graphql-ws v5.11.2
|
|
13
|
+
*
|
|
14
|
+
* References:
|
|
15
|
+
* - Original issue: https://github.com/apollographql/apollo-server/issues/1526
|
|
16
|
+
* - Community solution: https://github.com/apollographql/apollo-server/issues/1526#issuecomment-502884432
|
|
17
|
+
* - graphql-ws context: https://github.com/enisdenjo/graphql-ws#context
|
|
18
|
+
*/
|
|
19
|
+
export declare const constructDataSourcesForSubscriptions: (context: any, cache: any, dataSources: any) => any;
|
|
20
|
+
/**
|
|
21
|
+
* Creates the WebSocket subscription context
|
|
22
|
+
* This function is shared between GraphqlWs and WebsocketMultiPathServer
|
|
23
|
+
* to ensure consistent context creation across all subscription endpoints.
|
|
24
|
+
*
|
|
25
|
+
* @param ctx - The graphql-ws context containing connectionParams
|
|
26
|
+
* @param moduleService - The module service for creating context
|
|
27
|
+
* @param cache - Redis cache instance
|
|
28
|
+
* @returns Promise<object> - The complete subscription context
|
|
29
|
+
*/
|
|
30
|
+
export declare function createWebSocketContext(ctx: any, moduleService: IModuleService, cache: IORedis.Redis | IORedis.Cluster): Promise<any>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper function to construct data sources for WebSocket subscriptions
|
|
3
|
+
*
|
|
4
|
+
* @workaround DataSources are an Apollo Server feature that only work with HTTP requests.
|
|
5
|
+
* When using graphql-ws for WebSocket subscriptions, we must manually initialize data sources
|
|
6
|
+
* because graphql-ws has a separate context pipeline from Apollo Server's HTTP pipeline.
|
|
7
|
+
*
|
|
8
|
+
* This is necessary as of:
|
|
9
|
+
* - Apollo Server v4.10.4
|
|
10
|
+
* - graphql-ws v5.11.2
|
|
11
|
+
*
|
|
12
|
+
* References:
|
|
13
|
+
* - Original issue: https://github.com/apollographql/apollo-server/issues/1526
|
|
14
|
+
* - Community solution: https://github.com/apollographql/apollo-server/issues/1526#issuecomment-502884432
|
|
15
|
+
* - graphql-ws context: https://github.com/enisdenjo/graphql-ws#context
|
|
16
|
+
*/
|
|
17
|
+
const constructDataSourcesForSubscriptions = (context, cache, dataSources) => {
|
|
18
|
+
const initializeDataSource = (instance) => {
|
|
19
|
+
instance.initialize({ context, cache });
|
|
20
|
+
};
|
|
21
|
+
// tslint:disable-next-line:forin
|
|
22
|
+
for (const prop in dataSources) {
|
|
23
|
+
if (dataSources[prop] && typeof dataSources[prop]?.initialize === 'function') {
|
|
24
|
+
initializeDataSource(dataSources[prop]);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return dataSources;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Creates the WebSocket subscription context
|
|
31
|
+
* This function is shared between GraphqlWs and WebsocketMultiPathServer
|
|
32
|
+
* to ensure consistent context creation across all subscription endpoints.
|
|
33
|
+
*
|
|
34
|
+
* @param ctx - The graphql-ws context containing connectionParams
|
|
35
|
+
* @param moduleService - The module service for creating context
|
|
36
|
+
* @param cache - Redis cache instance
|
|
37
|
+
* @returns Promise<object> - The complete subscription context
|
|
38
|
+
*/
|
|
39
|
+
async function createWebSocketContext(ctx, moduleService, cache) {
|
|
40
|
+
try {
|
|
41
|
+
const connectionParams = ctx.connectionParams || {};
|
|
42
|
+
const pureContext = await moduleService.createContext(connectionParams, null);
|
|
43
|
+
const contextServices = await moduleService.serviceContext(connectionParams, null);
|
|
44
|
+
const context = {
|
|
45
|
+
...contextServices,
|
|
46
|
+
...pureContext,
|
|
47
|
+
preferences: moduleService.defaultPreferences,
|
|
48
|
+
...ctx,
|
|
49
|
+
};
|
|
50
|
+
const addons = {
|
|
51
|
+
dataSources: constructDataSourcesForSubscriptions(context, cache, moduleService.dataSource),
|
|
52
|
+
};
|
|
53
|
+
return {
|
|
54
|
+
...context,
|
|
55
|
+
...addons,
|
|
56
|
+
...ctx,
|
|
57
|
+
...pureContext,
|
|
58
|
+
preferences: moduleService.defaultPreferences,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
moduleService.logger.error('Error creating WebSocket context:', err);
|
|
63
|
+
// Return a minimal context to prevent crashes
|
|
64
|
+
return {
|
|
65
|
+
userContext: {},
|
|
66
|
+
req: {},
|
|
67
|
+
connectionParams: ctx.connectionParams || {},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}export{constructDataSourcesForSubscriptions,createWebSocketContext};//# sourceMappingURL=websocket-context.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket-context.mjs","sources":["../../src/servers/websocket-context.ts"],"sourcesContent":[null],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;AAeG;AACU,MAAA,oCAAoC,GAAG,CAAC,OAAY,EAAE,KAAU,EAAE,WAAgB,KAAI;AAC/F,IAAA,MAAM,o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AAC,KAAK,CAAC,mCAAmC,EAAE,GAAG,CAAC,CAAC;;QAErE,OAAO;AACH,YAAA,WAAW,EAAE,EAAE;AACf,YAAA,GAAG,EAAE,EAAE;AACP,YAAA,gBAAgB,EAAE,GAAG,CAAC,gBAAgB,IAAI,EAAE;SAC/C,CAAC;KACL;AACL"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@common-stack/server-stack",
|
|
3
|
-
"version": "7.2.1-alpha.
|
|
3
|
+
"version": "7.2.1-alpha.74",
|
|
4
4
|
"description": "common core for higher packages to depend on",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "CDMBase LLC",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"@cdm-logger/client": "^9.0.8",
|
|
33
33
|
"@cdm-logger/server": "^9.0.15",
|
|
34
34
|
"@cdmbase/graphql-type-uri": "^4.0.0",
|
|
35
|
-
"@common-stack/codegen-zod": "7.2.1-alpha.
|
|
36
|
-
"@common-stack/graphql-api": "7.2.1-alpha.
|
|
35
|
+
"@common-stack/codegen-zod": "7.2.1-alpha.74",
|
|
36
|
+
"@common-stack/graphql-api": "7.2.1-alpha.72",
|
|
37
37
|
"@graphql-tools/links": "~9.0.1",
|
|
38
38
|
"@graphql-tools/schema": "~10.0.6",
|
|
39
39
|
"@graphql-tools/stitch": "~9.2.10",
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"publishConfig": {
|
|
93
93
|
"access": "public"
|
|
94
94
|
},
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "a3834ae998bd4ef0c6f2652587e5338b4c73858b",
|
|
96
96
|
"typescript": {
|
|
97
97
|
"definition": "lib/index.d.ts"
|
|
98
98
|
}
|