@rxdi/graphql-pubsub 0.7.244 → 0.7.245

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/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,43 @@ 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
+ if (this.subscriptionServer) {
63
+ this.subscriptionServer.close();
64
+ this.subscriptionServer = null;
65
+ }
44
66
  const config = {
45
67
  execute: this.execute.bind(this),
46
68
  subscribe: this.subscribe.bind(this),
47
69
  schema: this.config.graphqlOptions.schema,
48
70
  onConnect(connectionParams) {
49
- // return connectionHookService.modifyHooks
50
- // .onSubConnection(connectionParams);
51
71
  return connectionParams;
52
72
  },
53
73
  onOperation: (connectionParams, params, webSocket) => {
54
74
  return params;
55
- // return connectionHookService.modifyHooks
56
- // .onSubOperation(
57
- // connectionParams,
58
- // params,
59
- // webSocket
60
- // );
61
75
  },
62
76
  };
63
77
  if (this.pubConfig.authentication) {
@@ -76,15 +90,18 @@ let SubscriptionService = class SubscriptionService {
76
90
  config.onDisconnect = auth.onSubDisconnect.bind(auth);
77
91
  }
78
92
  }
79
- new subscriptions_transport_ws_1.SubscriptionServer(config, Object.assign({ server: this.server.listener, path: '/subscriptions' }, this.pubConfig.subscriptionServerOptions));
93
+ this.subscriptionServer = new subscriptions_transport_ws_1.SubscriptionServer(config, Object.assign({ server: this.server.listener, path: '/subscriptions' }, this.pubConfig.subscriptionServerOptions));
80
94
  });
81
95
  }
82
96
  /**
83
- * Cross compatability graphql v15 and v16 for subscriptions
97
+ * Cross compatability graphql v15 and v16 for subscriptions.
98
+ * Schema is read from the live config reference so dynamic schema reloads
99
+ * (e.g. Lambforge specialize, hot module registration) take effect for
100
+ * subsequent operations on already-open WS connections.
84
101
  */
85
- execute(schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver) {
102
+ execute(_schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver) {
86
103
  return (0, execution_1.execute)({
87
- schema,
104
+ schema: this.config.graphqlOptions.schema,
88
105
  document,
89
106
  rootValue,
90
107
  contextValue,
@@ -94,12 +111,9 @@ let SubscriptionService = class SubscriptionService {
94
111
  subscribeFieldResolver,
95
112
  });
96
113
  }
97
- /**
98
- * Cross compatability graphql v15 and v16 for subscriptions
99
- */
100
- subscribe(schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver) {
114
+ subscribe(_schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver) {
101
115
  return (0, subscription_1.subscribe)({
102
- schema,
116
+ schema: this.config.graphqlOptions.schema,
103
117
  document,
104
118
  rootValue,
105
119
  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.245",
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.244",
33
+ "@rxdi/rabbitmq-pubsub": "^0.7.244",
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.244",
38
+ "@rxdi/graphql": "^0.7.244",
39
+ "@rxdi/hapi": "^0.7.244",
40
40
  "@types/graphql": "^14.5.0",
41
41
  "@types/hapi": "^18.0.4",
42
42
  "@types/node": "^25.0.3",