@common-stack/server-stack 7.2.1-alpha.8 → 7.2.1-alpha.81
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/config/env-config.cjs +2 -2
- package/lib/config/env-config.cjs.map +1 -1
- package/lib/config/env-config.mjs +2 -2
- package/lib/config/env-config.mjs.map +1 -1
- package/lib/infrastructure/infrastructure-factory.cjs +1 -1
- package/lib/infrastructure/infrastructure-factory.cjs.map +1 -1
- package/lib/infrastructure/infrastructure-factory.mjs +1 -1
- package/lib/infrastructure/infrastructure-factory.mjs.map +1 -1
- package/lib/infrastructure/inngest-factory.cjs +23 -2
- package/lib/infrastructure/inngest-factory.cjs.map +1 -1
- package/lib/infrastructure/inngest-factory.mjs +23 -2
- package/lib/infrastructure/inngest-factory.mjs.map +1 -1
- package/lib/inngest/handler-factory.d.ts +8 -2
- package/lib/inngest/middleware/auto-resolve-invoke.middleware.cjs +275 -0
- package/lib/inngest/middleware/auto-resolve-invoke.middleware.cjs.map +1 -0
- package/lib/inngest/middleware/auto-resolve-invoke.middleware.d.ts +111 -0
- package/lib/inngest/middleware/auto-resolve-invoke.middleware.mjs +275 -0
- package/lib/inngest/middleware/auto-resolve-invoke.middleware.mjs.map +1 -0
- package/lib/inngest/middleware/function-reference-helper.cjs +363 -0
- package/lib/inngest/middleware/function-reference-helper.cjs.map +1 -0
- package/lib/inngest/middleware/function-reference-helper.d.ts +211 -0
- package/lib/inngest/middleware/function-reference-helper.mjs +363 -0
- package/lib/inngest/middleware/function-reference-helper.mjs.map +1 -0
- package/lib/inngest/middleware/index.d.ts +31 -0
- package/lib/inngest/middleware/types.d.ts +162 -0
- package/lib/inngest/setup.cjs +31 -14
- package/lib/inngest/setup.cjs.map +1 -1
- package/lib/inngest/setup.mjs +31 -14
- package/lib/inngest/setup.mjs.map +1 -1
- 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 +8 -6
- package/lib/plugins/invalidateCachePlugin.test.d.ts +0 -1
- package/lib/plugins/response-cache-plugin.test.d.ts +0 -1
- package/lib/utils/add-shareable-directive-to-schema.test.d.ts +0 -1
package/lib/inngest/setup.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {serve}from'inngest/express';/**
|
|
1
|
+
import {serve}from'inngest/express';import {globalFunctionRegistry}from'./middleware/function-reference-helper.mjs';/**
|
|
2
2
|
* Sets up Inngest functions from the Feature system and registers the handler
|
|
3
3
|
*/
|
|
4
4
|
async function setupInngestFunctions(modules, app, serviceContainer, logger) {
|
|
@@ -6,33 +6,50 @@ async function setupInngestFunctions(modules, app, serviceContainer, logger) {
|
|
|
6
6
|
// Get Inngest client from the container (already bound in infraModule)
|
|
7
7
|
const inngestClient = serviceContainer.get('INNGEST_CLIENT');
|
|
8
8
|
logger.info('✅ Retrieved Inngest client from service container');
|
|
9
|
-
|
|
9
|
+
// Load Inngest functions from all modules
|
|
10
|
+
// The improved loadInngestFunctions now handles both array and object returns
|
|
11
|
+
const inngestFunctions = await modules.loadInngestFunctions({
|
|
10
12
|
container: serviceContainer,
|
|
11
13
|
inngest: inngestClient,
|
|
12
14
|
settings: {},
|
|
13
15
|
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
if (inngestFunctions.length > 0) {
|
|
17
|
+
logger.info(`✅ Loaded ${inngestFunctions.length} Inngest functions from Feature system`);
|
|
18
|
+
// Log function IDs for debugging
|
|
19
|
+
const functionIds = inngestFunctions
|
|
20
|
+
.filter((fn) => fn && fn.id)
|
|
21
|
+
.map((fn) => (typeof fn.id === 'function' ? fn.id() : fn.id))
|
|
22
|
+
.join(', ');
|
|
23
|
+
logger.debug(`Registering Inngest functions: ${functionIds}`);
|
|
24
|
+
// ✨ Register functions with global registry for referenceFunction() helper
|
|
25
|
+
logger.info('📝 Registering functions with global function registry...');
|
|
26
|
+
try {
|
|
27
|
+
globalFunctionRegistry.register(inngestFunctions);
|
|
28
|
+
logger.info(`✅ Registered ${globalFunctionRegistry.count} functions for referenceFunction() helper`);
|
|
29
|
+
logger.info('💡 You can now use: referenceFunction("function-id") or auto-invoke in step.invoke()');
|
|
17
30
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (flatFunctions.length > 0) {
|
|
31
|
+
catch (registryError) {
|
|
32
|
+
logger.error('❌ Error registering functions with global registry:', registryError);
|
|
33
|
+
}
|
|
34
|
+
// Register Inngest handler
|
|
35
|
+
logger.info('📞 Calling serve() to register Inngest handler...');
|
|
24
36
|
const inngestHandler = serve({
|
|
25
37
|
client: inngestClient,
|
|
26
|
-
functions:
|
|
38
|
+
functions: inngestFunctions,
|
|
27
39
|
});
|
|
40
|
+
logger.info('✅ serve() completed successfully');
|
|
28
41
|
app.use('/api/inngest', inngestHandler);
|
|
29
|
-
logger.info(`✅ Inngest handler registered with ${
|
|
42
|
+
logger.info(`✅ Inngest handler registered at /api/inngest with ${inngestFunctions.length} functions`);
|
|
30
43
|
}
|
|
31
44
|
else {
|
|
32
45
|
logger.info('No Inngest functions found - handler not registered');
|
|
33
46
|
}
|
|
34
47
|
}
|
|
35
48
|
catch (error) {
|
|
36
|
-
logger.warn('Inngest handler registration failed:', error
|
|
49
|
+
logger.warn('Inngest handler registration failed:', error?.message || String(error));
|
|
50
|
+
logger.debug('Full error stack:', error?.stack || error);
|
|
51
|
+
if (error && typeof error === 'object') {
|
|
52
|
+
logger.debug('Error keys:', Object.keys(error));
|
|
53
|
+
}
|
|
37
54
|
}
|
|
38
55
|
}export{setupInngestFunctions};//# sourceMappingURL=setup.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.mjs","sources":["../../src/inngest/setup.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"setup.mjs","sources":["../../src/inngest/setup.ts"],"sourcesContent":[null],"names":[],"mappings":"oHAWA;;AAEG;AACI,eAAe,qBAAqB,CACvC,OAAgB,EAChB,GAAY,EACZ,gBAA2B,EAC3B,MAAe,EAAA;AAEf,IAAA,IAAI;;QAEA,MAAM,aAAa,GAAG,gBAAgB,CAAC,GAAG,CAAU,gBAAgB,CAAC,CAAC;AACtE,QAAA,MAAM,CAAC,IAAI,CAAC,mDAAmD,CAAC,CAAC;;;AAIjE,QAAA,MAAM,gBAAgB,GAAG,MAAM,OAAO,CAAC,oBAAoB,CAAC;AACxD,YAAA,SAAS,EAAE,gBAAgB;AAC3B,YAAA,OAAO,EAAE,aAAa;AACtB,YAAA,QAAQ,EAAE,EAAE;AACf,SAAA,CAAC,CAAC;AAEH,QAAA,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE;YAC7B,MAAM,CAAC,IAAI,CAAC,CAAA,SAAA,EAAY,gBAAgB,CAAC,MAAM,CAAwC,sCAAA,CAAA,CAAC,CAAC;;YAGzF,MAAM,WAAW,GAAG,gBAAgB;iBAC/B,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;iBAC3B,GAAG,CAAC,CAAC,EAAE,MAAM,OAAO,EAAE,CAAC,EAAE,KAAK,UAAU,GAAG,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;iBAC5D,IAAI,CAAC,IAAI,CAAC,C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K,KAAK,QAAQ,EAAE;AACpC,YAAA,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;SACnD;KACJ;AACL"}
|
|
@@ -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;QA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'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,IA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Socket 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,"file":"websocket-context.cjs","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,oBAAoB,GAAG,CAAC,QAAa,KAAI;QAC3C,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,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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,oBAAoB,GAAG,CAAC,QAAa,KAAI;QAC3C,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,oBAAoB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;SAC3C;KACJ;AACD,IAAA,OAAO,WAAW,CAAC;AACvB,EAAE;AAEF;;;;;;;;;AASG;AACI,eAAe,sBAAsB,CACxC,GAAQ,EACR,aAA6B,EAC7B,KAAsC,EAAA;AAEtC,IAAA,IAAI;AACA,QAAA,MAAM,gBAAgB,GAAG,GAAG,CAAC,gBAAgB,IAAI,EAAE,CAAC;QACpD,MAAM,WAAW,GAAG,MAAM,aAAa,CAAC,aAAa,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;QAC9E,MAAM,eAAe,GAAG,MAAM,aAAa,CAAC,cAAc,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;AAEnF,QAAA,MAAM,OAAO,GAAG;AACZ,YAAA,GAAG,eAAe;AAClB,YAAA,GAAG,WAAW;YACd,WAAW,EAAE,aAAa,CAAC,kBAAkB;AAC7C,YAAA,GAAG,GAAG;SACT,CAAC;AAEF,QAAA,MAAM,MAAM,GAAG;YACX,WAAW,EAAE,oCAAoC,CAAC,OAAO,EAAE,KAAK,EAAE,aAAa,CAAC,UAAU,CAAC;SAC9F,CAAC;QAEF,OAAO;AACH,YAAA,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"}
|
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.81",
|
|
4
4
|
"description": "common core for higher packages to depend on",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "CDMBase LLC",
|
|
@@ -32,7 +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/
|
|
35
|
+
"@common-stack/codegen-zod": "7.2.1-alpha.81",
|
|
36
|
+
"@common-stack/graphql-api": "7.2.1-alpha.72",
|
|
36
37
|
"@graphql-tools/links": "~9.0.1",
|
|
37
38
|
"@graphql-tools/schema": "~10.0.6",
|
|
38
39
|
"@graphql-tools/stitch": "~9.2.10",
|
|
@@ -76,11 +77,12 @@
|
|
|
76
77
|
"rxjs": "^7.8.1",
|
|
77
78
|
"subscriptions-transport-ws": "^0.11.0",
|
|
78
79
|
"universal-cookie-express": "^4.0.1",
|
|
79
|
-
"ws": "^8.11.0"
|
|
80
|
+
"ws": "^8.11.0",
|
|
81
|
+
"zod": "^4.0.0"
|
|
80
82
|
},
|
|
81
83
|
"devDependencies": {
|
|
82
|
-
"@common-stack/server-core": "7.2.1-alpha.
|
|
83
|
-
"common": "7.2.1-alpha.
|
|
84
|
+
"@common-stack/server-core": "7.2.1-alpha.81",
|
|
85
|
+
"common": "7.2.1-alpha.66"
|
|
84
86
|
},
|
|
85
87
|
"peerDependencies": {
|
|
86
88
|
"@cdm-logger/core": ">=7.0.12",
|
|
@@ -90,7 +92,7 @@
|
|
|
90
92
|
"publishConfig": {
|
|
91
93
|
"access": "public"
|
|
92
94
|
},
|
|
93
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "57b5d3790618c54039ba0c685cf091b2d414316f",
|
|
94
96
|
"typescript": {
|
|
95
97
|
"definition": "lib/index.d.ts"
|
|
96
98
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|