@graphql-tools/executor-legacy-ws 1.0.1 → 1.0.2-rc-20230906221418-001cce4a

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/cjs/index.js CHANGED
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildWSLegacyExecutor = exports.LEGACY_WS = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const utils_1 = require("@graphql-tools/utils");
6
5
  const graphql_1 = require("graphql");
7
6
  const isomorphic_ws_1 = tslib_1.__importDefault(require("isomorphic-ws"));
7
+ const utils_1 = require("@graphql-tools/utils");
8
8
  var LEGACY_WS;
9
9
  (function (LEGACY_WS) {
10
10
  LEGACY_WS["CONNECTION_INIT"] = "connection_init";
@@ -19,6 +19,7 @@ var LEGACY_WS;
19
19
  LEGACY_WS["COMPLETE"] = "complete";
20
20
  })(LEGACY_WS || (exports.LEGACY_WS = LEGACY_WS = {}));
21
21
  function buildWSLegacyExecutor(subscriptionsEndpoint, WebSocketImpl, options) {
22
+ let executorConnectionParams = {};
22
23
  let websocket = null;
23
24
  const ensureWebsocket = (errorHandler = err => console.error(err)) => {
24
25
  if (websocket == null || websocket.readyState !== isomorphic_ws_1.default.OPEN) {
@@ -38,6 +39,7 @@ function buildWSLegacyExecutor(subscriptionsEndpoint, WebSocketImpl, options) {
38
39
  payload = options?.connectionParams;
39
40
  break;
40
41
  }
42
+ payload = Object.assign(payload, executorConnectionParams);
41
43
  websocket.send(JSON.stringify({
42
44
  type: LEGACY_WS.CONNECTION_INIT,
43
45
  payload,
@@ -65,6 +67,12 @@ function buildWSLegacyExecutor(subscriptionsEndpoint, WebSocketImpl, options) {
65
67
  }
66
68
  };
67
69
  return function legacyExecutor(request) {
70
+ // additional connection params can be supplied through the "connectionParams" field in extensions.
71
+ // TODO: connection params only from the FIRST operation in lazy mode will be used (detect connectionParams changes and reconnect, too implicit?)
72
+ if (request.extensions?.['connectionParams'] &&
73
+ typeof request.extensions?.['connectionParams'] === 'object') {
74
+ executorConnectionParams = Object.assign(executorConnectionParams, request.extensions['connectionParams']);
75
+ }
68
76
  const id = Date.now().toString();
69
77
  return (0, utils_1.observableToAsyncIterable)({
70
78
  subscribe(observer) {
package/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { observableToAsyncIterable } from '@graphql-tools/utils';
2
1
  import { print } from 'graphql';
3
2
  import WebSocket from 'isomorphic-ws';
3
+ import { observableToAsyncIterable } from '@graphql-tools/utils';
4
4
  export var LEGACY_WS;
5
5
  (function (LEGACY_WS) {
6
6
  LEGACY_WS["CONNECTION_INIT"] = "connection_init";
@@ -15,6 +15,7 @@ export var LEGACY_WS;
15
15
  LEGACY_WS["COMPLETE"] = "complete";
16
16
  })(LEGACY_WS || (LEGACY_WS = {}));
17
17
  export function buildWSLegacyExecutor(subscriptionsEndpoint, WebSocketImpl, options) {
18
+ let executorConnectionParams = {};
18
19
  let websocket = null;
19
20
  const ensureWebsocket = (errorHandler = err => console.error(err)) => {
20
21
  if (websocket == null || websocket.readyState !== WebSocket.OPEN) {
@@ -34,6 +35,7 @@ export function buildWSLegacyExecutor(subscriptionsEndpoint, WebSocketImpl, opti
34
35
  payload = options?.connectionParams;
35
36
  break;
36
37
  }
38
+ payload = Object.assign(payload, executorConnectionParams);
37
39
  websocket.send(JSON.stringify({
38
40
  type: LEGACY_WS.CONNECTION_INIT,
39
41
  payload,
@@ -61,6 +63,12 @@ export function buildWSLegacyExecutor(subscriptionsEndpoint, WebSocketImpl, opti
61
63
  }
62
64
  };
63
65
  return function legacyExecutor(request) {
66
+ // additional connection params can be supplied through the "connectionParams" field in extensions.
67
+ // TODO: connection params only from the FIRST operation in lazy mode will be used (detect connectionParams changes and reconnect, too implicit?)
68
+ if (request.extensions?.['connectionParams'] &&
69
+ typeof request.extensions?.['connectionParams'] === 'object') {
70
+ executorConnectionParams = Object.assign(executorConnectionParams, request.extensions['connectionParams']);
71
+ }
64
72
  const id = Date.now().toString();
65
73
  return observableToAsyncIterable({
66
74
  subscribe(observer) {
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@graphql-tools/executor-legacy-ws",
3
- "version": "1.0.1",
3
+ "version": "1.0.2-rc-20230906221418-001cce4a",
4
4
  "description": "A set of utils for faster development of GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
7
7
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
8
8
  },
9
9
  "dependencies": {
10
- "@types/ws": "^8.0.0",
11
10
  "@graphql-tools/utils": "^10.0.0",
11
+ "@types/ws": "^8.0.0",
12
12
  "isomorphic-ws": "5.0.0",
13
- "ws": "8.13.0",
14
- "tslib": "^2.4.0"
13
+ "tslib": "^2.4.0",
14
+ "ws": "8.14.0"
15
15
  },
16
16
  "repository": {
17
17
  "type": "git",
@@ -1,6 +1,6 @@
1
1
  /// <reference types="ws" />
2
- import { Executor } from '@graphql-tools/utils';
3
2
  import WebSocket from 'isomorphic-ws';
3
+ import { Executor } from '@graphql-tools/utils';
4
4
  export declare enum LEGACY_WS {
5
5
  CONNECTION_INIT = "connection_init",
6
6
  CONNECTION_ACK = "connection_ack",
@@ -14,7 +14,7 @@ export declare enum LEGACY_WS {
14
14
  COMPLETE = "complete"
15
15
  }
16
16
  export interface LegacyWSExecutorOpts {
17
- connectionParams?: Record<string, any>;
17
+ connectionParams?: Record<string, unknown> | (() => Record<string, unknown>);
18
18
  headers?: Record<string, any>;
19
19
  }
20
20
  export declare function buildWSLegacyExecutor(subscriptionsEndpoint: string, WebSocketImpl: typeof WebSocket, options?: LegacyWSExecutorOpts): Executor;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="ws" />
2
- import { Executor } from '@graphql-tools/utils';
3
2
  import WebSocket from 'isomorphic-ws';
3
+ import { Executor } from '@graphql-tools/utils';
4
4
  export declare enum LEGACY_WS {
5
5
  CONNECTION_INIT = "connection_init",
6
6
  CONNECTION_ACK = "connection_ack",
@@ -14,7 +14,7 @@ export declare enum LEGACY_WS {
14
14
  COMPLETE = "complete"
15
15
  }
16
16
  export interface LegacyWSExecutorOpts {
17
- connectionParams?: Record<string, any>;
17
+ connectionParams?: Record<string, unknown> | (() => Record<string, unknown>);
18
18
  headers?: Record<string, any>;
19
19
  }
20
20
  export declare function buildWSLegacyExecutor(subscriptionsEndpoint: string, WebSocketImpl: typeof WebSocket, options?: LegacyWSExecutorOpts): Executor;