@common-stack/server-stack 8.0.2-alpha.0 → 8.2.1-alpha.1
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/LICENSE +34 -21
- package/lib/MainStackServer.cjs +126 -146
- package/lib/MainStackServer.cjs.map +1 -1
- package/lib/MainStackServer.d.ts +12 -6
- package/lib/MainStackServer.mjs +126 -146
- package/lib/MainStackServer.mjs.map +1 -1
- package/lib/StackServer.cjs +23 -66
- package/lib/StackServer.cjs.map +1 -1
- package/lib/StackServer.d.ts +4 -5
- package/lib/StackServer.mjs +23 -66
- package/lib/StackServer.mjs.map +1 -1
- package/lib/api/schema-builder.cjs +13 -12
- package/lib/api/schema-builder.cjs.map +1 -1
- package/lib/api/schema-builder.mjs +13 -12
- package/lib/api/schema-builder.mjs.map +1 -1
- package/lib/api/sub-graph-schema-builder.cjs +147 -0
- package/lib/api/sub-graph-schema-builder.cjs.map +1 -0
- package/lib/api/sub-graph-schema-builder.d.ts +24 -0
- package/lib/api/sub-graph-schema-builder.mjs +147 -0
- package/lib/api/sub-graph-schema-builder.mjs.map +1 -0
- package/lib/config/env-config.cjs +6 -0
- package/lib/config/env-config.cjs.map +1 -1
- package/lib/config/env-config.d.ts +6 -0
- package/lib/config/env-config.mjs +6 -0
- package/lib/config/env-config.mjs.map +1 -1
- package/lib/examples/tenant-feature-example.d.ts +13 -0
- package/lib/examples/tenant-feature-integration.d.ts +14 -0
- package/lib/features/multi-module-example.d.ts +17 -0
- package/lib/index.cjs +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.mjs +1 -1
- package/lib/infrastructure/container-module.cjs +27 -0
- package/lib/infrastructure/container-module.cjs.map +1 -0
- package/lib/infrastructure/container-module.d.ts +3 -0
- package/lib/infrastructure/container-module.mjs +27 -0
- package/lib/infrastructure/container-module.mjs.map +1 -0
- package/lib/infrastructure/example-workflows.d.ts +16 -0
- package/lib/infrastructure/index.d.ts +5 -0
- package/lib/infrastructure/infrastructure-factory.cjs +172 -0
- package/lib/infrastructure/infrastructure-factory.cjs.map +1 -0
- package/lib/infrastructure/infrastructure-factory.d.ts +36 -0
- package/lib/infrastructure/infrastructure-factory.mjs +172 -0
- package/lib/infrastructure/infrastructure-factory.mjs.map +1 -0
- package/lib/infrastructure/inngest-factory.cjs +47 -0
- package/lib/infrastructure/inngest-factory.cjs.map +1 -0
- package/lib/infrastructure/inngest-factory.d.ts +8 -0
- package/lib/infrastructure/inngest-factory.mjs +47 -0
- package/lib/infrastructure/inngest-factory.mjs.map +1 -0
- package/lib/infrastructure/types.d.ts +28 -0
- package/lib/infrastructure/usage-examples.d.ts +9 -0
- package/lib/infrastructure/workflow-orchestrator.cjs +59 -0
- package/lib/infrastructure/workflow-orchestrator.cjs.map +1 -0
- package/lib/infrastructure/workflow-orchestrator.d.ts +10 -0
- package/lib/infrastructure/workflow-orchestrator.mjs +59 -0
- package/lib/infrastructure/workflow-orchestrator.mjs.map +1 -0
- package/lib/inngest/client-id-generator.d.ts +29 -0
- package/lib/inngest/handler-factory.d.ts +24 -0
- 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/multi-module-functions.d.ts +133 -0
- package/lib/inngest/setup.cjs +55 -0
- package/lib/inngest/setup.cjs.map +1 -0
- package/lib/inngest/setup.d.ts +10 -0
- package/lib/inngest/setup.mjs +55 -0
- package/lib/inngest/setup.mjs.map +1 -0
- package/lib/interfaces/graphql-request-context.d.ts +5 -0
- package/lib/middleware/index.d.ts +5 -0
- package/lib/middleware/redis-client.cjs +18 -0
- package/lib/middleware/redis-client.cjs.map +1 -0
- package/lib/middleware/redis-client.d.ts +16 -0
- package/lib/middleware/redis-client.mjs +18 -0
- package/lib/middleware/redis-client.mjs.map +1 -0
- package/lib/plugins/responseCachePlugin.cjs +2 -2
- package/lib/plugins/responseCachePlugin.cjs.map +1 -1
- package/lib/plugins/responseCachePlugin.mjs +2 -2
- package/lib/plugins/responseCachePlugin.mjs.map +1 -1
- package/lib/servers/ExpressApp.cjs +8 -3
- package/lib/servers/ExpressApp.cjs.map +1 -1
- package/lib/servers/ExpressApp.d.ts +1 -1
- package/lib/servers/ExpressApp.mjs +8 -3
- package/lib/servers/ExpressApp.mjs.map +1 -1
- package/lib/servers/GraphqlServer.cjs +7 -2
- package/lib/servers/GraphqlServer.cjs.map +1 -1
- package/lib/servers/GraphqlServer.d.ts +8 -6
- package/lib/servers/GraphqlServer.mjs +7 -2
- package/lib/servers/GraphqlServer.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/mongodb-migration-update.d.ts +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/lib/utils/add-shareable-directive-to-schema.cjs +44 -0
- package/lib/utils/add-shareable-directive-to-schema.cjs.map +1 -0
- package/lib/utils/add-shareable-directive-to-schema.d.ts +1 -0
- package/lib/utils/add-shareable-directive-to-schema.mjs +44 -0
- package/lib/utils/add-shareable-directive-to-schema.mjs.map +1 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/safe-model-factory.d.ts +18 -0
- package/package.json +15 -11
- package/lib/api/resolver.cjs +0 -12
- package/lib/api/resolver.cjs.map +0 -1
- package/lib/api/resolver.mjs +0 -12
- package/lib/api/resolver.mjs.map +0 -1
- package/lib/api/root-schema.graphqls.cjs +0 -2
- package/lib/api/root-schema.graphqls.cjs.map +0 -1
- package/lib/api/root-schema.graphqls.mjs +0 -2
- package/lib/api/root-schema.graphqls.mjs.map +0 -1
- package/lib/api/scalar.cjs +0 -16
- package/lib/api/scalar.cjs.map +0 -1
- package/lib/api/scalar.mjs +0 -16
- package/lib/api/scalar.mjs.map +0 -1
- package/lib/graphql/directives/index.cjs +0 -10
- package/lib/graphql/directives/index.cjs.map +0 -1
- package/lib/graphql/directives/index.d.ts +0 -7
- package/lib/graphql/directives/index.mjs +0 -10
- package/lib/graphql/directives/index.mjs.map +0 -1
- package/lib/graphql/index.d.ts +0 -2
- package/lib/graphql/schema/directives.graphql.cjs +0 -1
- package/lib/graphql/schema/directives.graphql.cjs.map +0 -1
- package/lib/graphql/schema/directives.graphql.mjs +0 -1
- package/lib/graphql/schema/directives.graphql.mjs.map +0 -1
- package/lib/graphql/schema/index.cjs +0 -1
- package/lib/graphql/schema/index.cjs.map +0 -1
- package/lib/graphql/schema/index.d.ts +0 -1
- package/lib/graphql/schema/index.mjs +0 -1
- package/lib/graphql/schema/index.mjs.map +0 -1
- package/lib/plugins/invalidateCachePlugin.test.d.ts +0 -1
- package/lib/plugins/response-cache-plugin.test.d.ts +0 -1
|
@@ -18,9 +18,10 @@ class GraphqlServer {
|
|
|
18
18
|
enableSubscription;
|
|
19
19
|
cacheKeyGenerator;
|
|
20
20
|
invalidateCacheKeyGenerator;
|
|
21
|
+
plugins;
|
|
21
22
|
logger;
|
|
22
23
|
graphqlWsServer;
|
|
23
|
-
constructor(app, httpServer, redisClient, moduleService, enableSubscription = true, cacheKeyGenerator, invalidateCacheKeyGenerator) {
|
|
24
|
+
constructor(app, httpServer, redisClient, moduleService, enableSubscription = true, cacheKeyGenerator, invalidateCacheKeyGenerator, plugins) {
|
|
24
25
|
this.app = app;
|
|
25
26
|
this.httpServer = httpServer;
|
|
26
27
|
this.redisClient = redisClient;
|
|
@@ -28,6 +29,7 @@ class GraphqlServer {
|
|
|
28
29
|
this.enableSubscription = enableSubscription;
|
|
29
30
|
this.cacheKeyGenerator = cacheKeyGenerator;
|
|
30
31
|
this.invalidateCacheKeyGenerator = invalidateCacheKeyGenerator;
|
|
32
|
+
this.plugins = plugins;
|
|
31
33
|
this.logger = this.moduleService.logger.child({ className: 'GraphqlServer' });
|
|
32
34
|
if (enableSubscription) {
|
|
33
35
|
const wsServer = new WebSocketServer({
|
|
@@ -39,7 +41,9 @@ class GraphqlServer {
|
|
|
39
41
|
}
|
|
40
42
|
async initialize() {
|
|
41
43
|
this.logger.info('GraphqlServer initializing...');
|
|
42
|
-
this.graphqlWsServer
|
|
44
|
+
if (this.graphqlWsServer) {
|
|
45
|
+
this.graphqlWsServer.create();
|
|
46
|
+
}
|
|
43
47
|
const apolloServer = this.configureApolloServer();
|
|
44
48
|
await apolloServer.start();
|
|
45
49
|
const corsOptions = {
|
|
@@ -122,6 +126,7 @@ class GraphqlServer {
|
|
|
122
126
|
ApolloServerPluginCacheControl(),
|
|
123
127
|
invalidateCachePlugin({ cache: this.redisClient, invalidateCacheKeyGenerator }),
|
|
124
128
|
responseCachePlugin({ logger, cacheKeyGenerator }),
|
|
129
|
+
...(this.plugins ?? []),
|
|
125
130
|
],
|
|
126
131
|
};
|
|
127
132
|
if (this.enableSubscription) {
|
|
@@ -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":"wsBAuBA,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;AAMD,IAAA,GAAA,CAAA;AACA,IAAA,UAAA,CAAA;AACA,IAAA,WAAA,CAAA;AACA,IAAA,aAAA,CAAA;AACA,IAAA,kBAAA,CAAA;AACA,IAAA,iBAAA,CAAA;AACA,IAAA,2BAAA,CAAA;AACA,IAAA,OAAA,CAAA;AAZb,IAAA,MAAM,CAAU;AAEhB,IAAA,eAAe,CAAmB;AAE1C,IAAA,WAAA,CACqB,GAAY,EACZ,UAAuB,EACvB,WAA4C,EAC5C,aAA6B,EAC7B,kBAAA,GAAqB,IAAI,EACzB,iBAAgC,EAChC,2BAAsD,EACtD,OAAmC,EAAA;QAPnC,IAAG,CAAA,GAAA,GAAH,GAAG,CAAS;QACZ,IAAU,CAAA,UAAA,GAAV,UAAU,CAAa;QACvB,IAAW,CAA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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"}
|
|
@@ -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,WA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 -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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
|
|
|
1
|
-
import { IModuleService } from '../interfaces';
|
|
2
1
|
import { Schema, Connection as DBConnection } from 'mongoose';
|
|
2
|
+
import { IModuleService } from '../interfaces';
|
|
3
3
|
export declare const MigrationSchema: Schema<any, import("mongoose").Model<any, any, any, any, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, {
|
|
4
4
|
name: string;
|
|
5
5
|
migrated_at?: Date;
|
|
@@ -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,"file":"websocket-context.cjs","sources":["../../src/servers/websocket-context.ts"],"sourcesContent":[null],"names":[],"mappings":"aAGA;;;;;;;;;;;;;;;AAeG;AACU,MAAA,oC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C,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,oBAAoB,GAAG,CAAC,QAAa,KAAI;QAC3C,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;AAC5C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E,EAAE;AACP,YAAA,gBAAgB,EAAE,GAAG,CAAC,gBAAgB,IAAI,EAAE;SAC/C,CAAC;KACL;AACL"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';var graphql=require('graphql');const addShareableDirectiveToSchema = (schemaString) => {
|
|
2
|
+
const ast = graphql.parse(schemaString);
|
|
3
|
+
const modifiedAst = graphql.visit(ast, {
|
|
4
|
+
ObjectTypeDefinition(node) {
|
|
5
|
+
// Add @shareable directive to each type
|
|
6
|
+
const shareableDirective = {
|
|
7
|
+
kind: graphql.Kind.DIRECTIVE,
|
|
8
|
+
name: { kind: graphql.Kind.NAME, value: 'shareable' },
|
|
9
|
+
};
|
|
10
|
+
return {
|
|
11
|
+
...node,
|
|
12
|
+
directives: [...(node.directives || []), shareableDirective],
|
|
13
|
+
};
|
|
14
|
+
},
|
|
15
|
+
ObjectTypeExtension(node) {
|
|
16
|
+
// Add @shareable directive to each extended type
|
|
17
|
+
const shareableDirective = {
|
|
18
|
+
kind: graphql.Kind.DIRECTIVE,
|
|
19
|
+
name: { kind: graphql.Kind.NAME, value: 'shareable' },
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
...node,
|
|
23
|
+
directives: [...(node.directives || []), shareableDirective],
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
FieldDefinition(node, _key, _parent, _path, ancestors) {
|
|
27
|
+
// Get the parent type definition from ancestors
|
|
28
|
+
const parent = ancestors[2];
|
|
29
|
+
// @ts-expect-error - parent is an object, but we need to check if it has a kind property
|
|
30
|
+
if (parent?.kind === graphql.Kind.OBJECT_TYPE_DEFINITION && parent.name.value === 'Query') {
|
|
31
|
+
const shareableDirective = {
|
|
32
|
+
kind: graphql.Kind.DIRECTIVE,
|
|
33
|
+
name: { kind: graphql.Kind.NAME, value: 'shareable' },
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
...node,
|
|
37
|
+
directives: [...(node.directives || []), shareableDirective],
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return node;
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
return graphql.print(modifiedAst);
|
|
44
|
+
};exports.addShareableDirectiveToSchema=addShareableDirectiveToSchema;//# sourceMappingURL=add-shareable-directive-to-schema.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-shareable-directive-to-schema.cjs","sources":["../../src/utils/add-shareable-directive-to-schema.ts"],"sourcesContent":[null],"names":["parse","visit","Kind","print"],"mappings":"4CAEa,MAAA,6BAA6B,GAAG,CAAC,YAAoB,KAAI;AAClE,IAAA,MAAM,GAAG,GAAGA,aAAK,CAAC,YAAY,CAAC,CAAC;AAEhC,IAAA,MAAM,WAAW,GAAGC,aAAK,CAAC,GAAG,EAAE;AAC3B,QAAA,oBAAoB,CAAC,IAAI,EAAA;;AAErB,YAAA,MAAM,kBAAkB,GAAG;gBACvB,IAAI,EAAEC,YAAI,CAAC,SAAS;gBACpB,IAAI,EAAE,EAAE,IAAI,EAAEA,YAAI,CAAC,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE;aAChD,CAAC;YAEF,OAAO;AACH,gBAAA,GAAG,IAAI;AACP,gBAAA,UAAU,EAAE,CAAC,IAAI,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE,kBAAkB,CAAC;aAC/D,CAAC;SACL;AACD,QAAA,mBAAmB,CAAC,IAAI,EAAA;;AAEpB,YAAA,MAAM,kBAAkB,GAAG;gBACvB,IAAI,EAAEA,YAAI,CAAC,SAAS;gBACpB,IAAI,EAAE,EAAE,IAAI,EAAEA,YAAI,CAAC,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE;aAChD,CAAC;YAEF,OAAO;AACH,gBAAA,GAAG,IAAI;AACP,gBAAA,UAAU,EAAE,CAAC,IAAI,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE,kBAAkB,CAAC;aAC/D,CAAC;SACL;QACD,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAA;;AAEjD,YAAA,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;;AAE5B,YAAA,IAAI,MAAM,EAAE,IAAI,KAAKA,YAAI,CAAC,sBAAsB,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,KAAK,OAAO,EAAE;AAC/E,gBAAA,MAAM,kBAAkB,GAAG;oBACvB,IAAI,EAAEA,YAAI,CAAC,SAAS;oBACpB,IAAI,EAAE,EAAE,IAAI,EAAEA,YAAI,CAAC,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE;iBAChD,CAAC;gBAEF,OAAO;AACH,oBAAA,GAAG,IAAI;AACP,oBAAA,UAAU,EAAE,CAAC,IAAI,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE,kBAAkB,CAAC;iBAC/D,CAAC;aACL;AACD,YAAA,OAAO,IAAI,CAAC;SACf;AACJ,KAAA,CAAC,CAAC;AAEH,IAAA,OAAOC,aAAK,CAAC,WAAW,CAAC,CAAC;AAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const addShareableDirectiveToSchema: (schemaString: string) => string;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {parse,visit,Kind,print}from'graphql';const addShareableDirectiveToSchema = (schemaString) => {
|
|
2
|
+
const ast = parse(schemaString);
|
|
3
|
+
const modifiedAst = visit(ast, {
|
|
4
|
+
ObjectTypeDefinition(node) {
|
|
5
|
+
// Add @shareable directive to each type
|
|
6
|
+
const shareableDirective = {
|
|
7
|
+
kind: Kind.DIRECTIVE,
|
|
8
|
+
name: { kind: Kind.NAME, value: 'shareable' },
|
|
9
|
+
};
|
|
10
|
+
return {
|
|
11
|
+
...node,
|
|
12
|
+
directives: [...(node.directives || []), shareableDirective],
|
|
13
|
+
};
|
|
14
|
+
},
|
|
15
|
+
ObjectTypeExtension(node) {
|
|
16
|
+
// Add @shareable directive to each extended type
|
|
17
|
+
const shareableDirective = {
|
|
18
|
+
kind: Kind.DIRECTIVE,
|
|
19
|
+
name: { kind: Kind.NAME, value: 'shareable' },
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
...node,
|
|
23
|
+
directives: [...(node.directives || []), shareableDirective],
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
FieldDefinition(node, _key, _parent, _path, ancestors) {
|
|
27
|
+
// Get the parent type definition from ancestors
|
|
28
|
+
const parent = ancestors[2];
|
|
29
|
+
// @ts-expect-error - parent is an object, but we need to check if it has a kind property
|
|
30
|
+
if (parent?.kind === Kind.OBJECT_TYPE_DEFINITION && parent.name.value === 'Query') {
|
|
31
|
+
const shareableDirective = {
|
|
32
|
+
kind: Kind.DIRECTIVE,
|
|
33
|
+
name: { kind: Kind.NAME, value: 'shareable' },
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
...node,
|
|
37
|
+
directives: [...(node.directives || []), shareableDirective],
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return node;
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
return print(modifiedAst);
|
|
44
|
+
};export{addShareableDirectiveToSchema};//# sourceMappingURL=add-shareable-directive-to-schema.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-shareable-directive-to-schema.mjs","sources":["../../src/utils/add-shareable-directive-to-schema.ts"],"sourcesContent":[null],"names":[],"mappings":"6CAEa,MAAA,6BAA6B,GAAG,CAAC,YAAoB,KAAI;AAClE,IAAA,MAAM,GAAG,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;AAEhC,IAAA,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,EAAE;AAC3B,QAAA,oBAAoB,CAAC,IAAI,EAAA;;AAErB,YAAA,MAAM,kBAAkB,GAAG;gBACvB,IAAI,EAAE,IAAI,CAAC,SAAS;gBACpB,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KA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/lib/utils/index.d.ts
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Connection, Model, Schema } from 'mongoose';
|
|
2
|
+
/**
|
|
3
|
+
* Safely creates or retrieves a Mongoose model, preventing "Cannot overwrite model once compiled" errors
|
|
4
|
+
*
|
|
5
|
+
* @param db - MongoDB connection
|
|
6
|
+
* @param modelName - Name of the model
|
|
7
|
+
* @param schema - Mongoose schema (only used if model doesn't exist)
|
|
8
|
+
* @returns The Mongoose model
|
|
9
|
+
*/
|
|
10
|
+
export declare function safeModelFactory<T = any>(db: Connection, modelName: string, schema?: Schema<T>): Model<T>;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a model factory function that uses safe model registration
|
|
13
|
+
*
|
|
14
|
+
* @param modelName - Name of the model
|
|
15
|
+
* @param schema - Mongoose schema
|
|
16
|
+
* @returns A factory function that safely creates/retrieves the model
|
|
17
|
+
*/
|
|
18
|
+
export declare function createSafeModelFactory<T = any>(modelName: string, schema: Schema<T>): (db: Connection) => Model<T>;
|