@rxdi/graphql-pubsub 0.7.244 → 0.7.246

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.
@@ -38,6 +38,7 @@ export declare class GRAPHQL_PUB_SUB_DI_CONFIG {
38
38
  log?: boolean;
39
39
  activateRabbitMQ?: boolean;
40
40
  protocol?: PubSubProtocol;
41
+ path?: string;
41
42
  logger?: any;
42
43
  subscriptionServerOptions?: GRAPHQL_PUBSUB_SERVER_OPTIONS;
43
44
  }
package/dist/index.js CHANGED
@@ -29,6 +29,15 @@ const pub_sub_service_1 = require("./services/pub-sub.service");
29
29
  const logger_service_1 = require("./services/logger.service");
30
30
  let GraphQLPubSubModule = GraphQLPubSubModule_1 = class GraphQLPubSubModule {
31
31
  static forRoot(config) {
32
+ // Idempotent path: if GRAPHQL_PUB_SUB_CONFIG is already in the container,
33
+ // merge into the live config. SubscriptionService reads this on its next
34
+ // register() — which the GraphqlService schema-reload hook triggers
35
+ // automatically once the user module finishes wiring controllers.
36
+ if (core_1.Container.has(config_tokens_1.GRAPHQL_PUB_SUB_CONFIG)) {
37
+ const live = core_1.Container.get(config_tokens_1.GRAPHQL_PUB_SUB_CONFIG);
38
+ Object.assign(live, config || new config_tokens_1.GRAPHQL_PUB_SUB_DI_CONFIG());
39
+ return { module: GraphQLPubSubModule_1, providers: [] };
40
+ }
32
41
  return {
33
42
  module: GraphQLPubSubModule_1,
34
43
  providers: [
@@ -2,19 +2,26 @@ import { PluginInterface } from '@rxdi/core';
2
2
  import { Server } from '@hapi/hapi';
3
3
  import { GRAPHQL_PLUGIN_CONFIG } from '@rxdi/graphql';
4
4
  import { GRAPHQL_PUB_SUB_DI_CONFIG } from '../config.tokens';
5
+ import { GraphQLSchema } from 'graphql';
5
6
  export declare class SubscriptionService implements PluginInterface {
6
7
  private server;
7
8
  private config;
8
9
  private pubConfig;
10
+ private subscriptionServer;
9
11
  constructor(server: Server, config: GRAPHQL_PLUGIN_CONFIG, pubConfig: GRAPHQL_PUB_SUB_DI_CONFIG);
10
12
  OnInit(): void;
11
- register(): Promise<void>;
12
13
  /**
13
- * Cross compatability graphql v15 and v16 for subscriptions
14
+ * Safe to call multiple times. On re-invocation, the previous SubscriptionServer
15
+ * is closed and a new one is bound — this is what makes dynamic schema reloads
16
+ * (e.g. Lambforge specialize) actually take effect for WS subscribers.
14
17
  */
15
- private execute;
18
+ register(schema?: GraphQLSchema): Promise<void>;
16
19
  /**
17
- * Cross compatability graphql v15 and v16 for subscriptions
20
+ * Cross compatability graphql v15 and v16 for subscriptions.
21
+ * Schema is read from the live config reference so dynamic schema reloads
22
+ * (e.g. Lambforge specialize, hot module registration) take effect for
23
+ * subsequent operations on already-open WS connections.
18
24
  */
25
+ private execute;
19
26
  private subscribe;
20
27
  }
@@ -35,29 +35,52 @@ let SubscriptionService = class SubscriptionService {
35
35
  this.server = server;
36
36
  this.config = config;
37
37
  this.pubConfig = pubConfig;
38
+ this.subscriptionServer = null;
38
39
  }
39
40
  OnInit() {
40
41
  this.register();
42
+ // Forward-only coupling on graphql: ask GraphqlService to call us back
43
+ // on schema reload so the WS server rebinds against the new schema.
44
+ try {
45
+ const graphqlService = core_1.Container.get(graphql_1.GraphqlService);
46
+ graphqlService.addSchemaReloadHook((schema) => this.register(schema));
47
+ }
48
+ catch (e) {
49
+ // GraphqlService unavailable in this container — unusual but not fatal.
50
+ }
41
51
  }
42
- register() {
52
+ /**
53
+ * Safe to call multiple times. On re-invocation, the previous SubscriptionServer
54
+ * is closed and a new one is bound — this is what makes dynamic schema reloads
55
+ * (e.g. Lambforge specialize) actually take effect for WS subscribers.
56
+ */
57
+ register(schema) {
43
58
  return __awaiter(this, void 0, void 0, function* () {
59
+ if (schema) {
60
+ this.config.graphqlOptions.schema = schema;
61
+ }
62
+ // During lambda specialize the user module is loaded with
63
+ // LAMBFORGE_RUNTIME=1. If a schema-reload hook fires during
64
+ // that transient phase, update the config reference but leave
65
+ // the existing server intact — it is recreated in step 2 of
66
+ // specialize (applyAppModule → reloadSchema) when the flag
67
+ // is no longer set.
68
+ if (process.env.LAMBFORGE_RUNTIME) {
69
+ return;
70
+ }
71
+ if (this.subscriptionServer) {
72
+ this.subscriptionServer.close();
73
+ this.subscriptionServer = null;
74
+ }
44
75
  const config = {
45
76
  execute: this.execute.bind(this),
46
77
  subscribe: this.subscribe.bind(this),
47
78
  schema: this.config.graphqlOptions.schema,
48
79
  onConnect(connectionParams) {
49
- // return connectionHookService.modifyHooks
50
- // .onSubConnection(connectionParams);
51
80
  return connectionParams;
52
81
  },
53
82
  onOperation: (connectionParams, params, webSocket) => {
54
- return params;
55
- // return connectionHookService.modifyHooks
56
- // .onSubOperation(
57
- // connectionParams,
58
- // params,
59
- // webSocket
60
- // );
83
+ return Object.assign(Object.assign({}, params), { schema: this.config.graphqlOptions.schema });
61
84
  },
62
85
  };
63
86
  if (this.pubConfig.authentication) {
@@ -76,15 +99,18 @@ let SubscriptionService = class SubscriptionService {
76
99
  config.onDisconnect = auth.onSubDisconnect.bind(auth);
77
100
  }
78
101
  }
79
- new subscriptions_transport_ws_1.SubscriptionServer(config, Object.assign({ server: this.server.listener, path: '/subscriptions' }, this.pubConfig.subscriptionServerOptions));
102
+ this.subscriptionServer = new subscriptions_transport_ws_1.SubscriptionServer(config, Object.assign({ server: this.server.listener }, this.pubConfig.subscriptionServerOptions));
80
103
  });
81
104
  }
82
105
  /**
83
- * Cross compatability graphql v15 and v16 for subscriptions
106
+ * Cross compatability graphql v15 and v16 for subscriptions.
107
+ * Schema is read from the live config reference so dynamic schema reloads
108
+ * (e.g. Lambforge specialize, hot module registration) take effect for
109
+ * subsequent operations on already-open WS connections.
84
110
  */
85
- execute(schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver) {
111
+ execute(_schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver) {
86
112
  return (0, execution_1.execute)({
87
- schema,
113
+ schema: this.config.graphqlOptions.schema,
88
114
  document,
89
115
  rootValue,
90
116
  contextValue,
@@ -94,12 +120,9 @@ let SubscriptionService = class SubscriptionService {
94
120
  subscribeFieldResolver,
95
121
  });
96
122
  }
97
- /**
98
- * Cross compatability graphql v15 and v16 for subscriptions
99
- */
100
- subscribe(schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver) {
123
+ subscribe(_schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver) {
101
124
  return (0, subscription_1.subscribe)({
102
- schema,
125
+ schema: this.config.graphqlOptions.schema,
103
126
  document,
104
127
  rootValue,
105
128
  contextValue,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rxdi/graphql-pubsub",
3
- "version": "0.7.244",
3
+ "version": "0.7.246",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/rxdi/graphql-pubsub"
@@ -29,14 +29,14 @@
29
29
  },
30
30
  "homepage": "https://github.com/rxdi/graphql-pubsub#readme",
31
31
  "dependencies": {
32
- "@rxdi/graphql-rabbitmq-subscriptions": "^0.7.243",
33
- "@rxdi/rabbitmq-pubsub": "^0.7.243",
32
+ "@rxdi/graphql-rabbitmq-subscriptions": "^0.7.245",
33
+ "@rxdi/rabbitmq-pubsub": "^0.7.245",
34
34
  "subscriptions-transport-ws": "^0.9.19"
35
35
  },
36
36
  "devDependencies": {
37
- "@rxdi/core": "^0.7.243",
38
- "@rxdi/graphql": "^0.7.243",
39
- "@rxdi/hapi": "^0.7.243",
37
+ "@rxdi/core": "^0.7.245",
38
+ "@rxdi/graphql": "^0.7.245",
39
+ "@rxdi/hapi": "^0.7.245",
40
40
  "@types/graphql": "^14.5.0",
41
41
  "@types/hapi": "^18.0.4",
42
42
  "@types/node": "^25.0.3",