@graphql-tools/executor-graphql-ws 3.2.1 → 3.2.2-alpha-b41f442e4b1825290a8d4d3f94175f882a5f70c9

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @graphql-tools/executor-graphql-ws
2
2
 
3
+ ## 3.2.2-alpha-b41f442e4b1825290a8d4d3f94175f882a5f70c9
4
+ ### Patch Changes
5
+
6
+
7
+
8
+ - [`2de8d6a`](https://github.com/graphql-hive/gateway/commit/2de8d6a244af2d6b8b3c5dee7cd362942dafd0e9) Thanks [@enisdenjo](https://github.com/enisdenjo)! - Do not carry `extensions.connectionParams` over between executions and do not mutate the `connectionParams` option
9
+
3
10
  ## 3.2.1
4
11
  ### Patch Changes
5
12
 
package/dist/index.cjs CHANGED
@@ -23,7 +23,8 @@ function isClient(client) {
23
23
  }
24
24
  function buildGraphQLWSExecutor(clientOptionsOrClient) {
25
25
  let graphqlWSClient;
26
- let executorConnectionParams = {};
26
+ const clientsByConnectionParams = /* @__PURE__ */ new Map();
27
+ let getClient = (_extensionsConnectionParams) => graphqlWSClient;
27
28
  let printFn = executorCommon.defaultPrintFn;
28
29
  if (isClient(clientOptionsOrClient)) {
29
30
  graphqlWSClient = clientOptionsOrClient;
@@ -54,20 +55,37 @@ function buildGraphQLWSExecutor(clientOptionsOrClient) {
54
55
  }
55
56
  }
56
57
  } : isows.WebSocket;
57
- graphqlWSClient = graphqlWs.createClient({
58
- url: clientOptionsOrClient.url,
59
- webSocketImpl,
60
- lazy: clientOptionsOrClient.lazy !== false,
61
- lazyCloseTimeout: clientOptionsOrClient.lazyCloseTimeout || 0,
62
- connectionParams: () => {
63
- const optionsConnectionParams = (typeof clientOptionsOrClient.connectionParams === "function" ? clientOptionsOrClient.connectionParams() : clientOptionsOrClient.connectionParams) || {};
64
- return Object.assign(optionsConnectionParams, executorConnectionParams);
65
- },
66
- on: clientOptionsOrClient.on
67
- });
68
- if (clientOptionsOrClient.onClient) {
69
- clientOptionsOrClient.onClient(graphqlWSClient);
70
- }
58
+ const clientOptions = clientOptionsOrClient;
59
+ const createWSClient = (extensionsConnectionParams) => {
60
+ const client = graphqlWs.createClient({
61
+ url: clientOptions.url,
62
+ webSocketImpl,
63
+ lazy: clientOptions.lazy !== false,
64
+ lazyCloseTimeout: clientOptions.lazyCloseTimeout || 0,
65
+ connectionParams: () => ({
66
+ ...typeof clientOptions.connectionParams === "function" ? clientOptions.connectionParams() : clientOptions.connectionParams,
67
+ ...extensionsConnectionParams
68
+ }),
69
+ on: clientOptions.on
70
+ });
71
+ if (clientOptions.onClient) {
72
+ clientOptions.onClient(client);
73
+ }
74
+ return client;
75
+ };
76
+ graphqlWSClient = createWSClient();
77
+ getClient = (extensionsConnectionParams) => {
78
+ if (!extensionsConnectionParams) {
79
+ return graphqlWSClient;
80
+ }
81
+ const key = JSON.stringify(extensionsConnectionParams);
82
+ let client = clientsByConnectionParams.get(key);
83
+ if (!client) {
84
+ client = createWSClient({ ...extensionsConnectionParams });
85
+ clientsByConnectionParams.set(key, client);
86
+ }
87
+ return client;
88
+ };
71
89
  }
72
90
  const executor = function GraphQLWSExecutor(executionRequest) {
73
91
  const {
@@ -76,15 +94,8 @@ function buildGraphQLWSExecutor(clientOptionsOrClient) {
76
94
  info,
77
95
  signal = info?.signal
78
96
  } = executionRequest;
79
- if (extensions?.["connectionParams"] && typeof extensions?.["connectionParams"] === "object") {
80
- executorConnectionParams = Object.assign(
81
- executorConnectionParams,
82
- extensions["connectionParams"]
83
- );
84
- }
85
- const iterableIterator = graphqlWSClient.iterate(
86
- executorCommon.serializeExecutionRequest({ executionRequest, printFn })
87
- );
97
+ const extensionsConnectionParams = extensions?.["connectionParams"] && typeof extensions?.["connectionParams"] === "object" ? extensions["connectionParams"] : void 0;
98
+ const iterableIterator = getClient(extensionsConnectionParams).iterate(executorCommon.serializeExecutionRequest({ executionRequest, printFn }));
88
99
  if (iterableIterator.return && signal) {
89
100
  signal.addEventListener(
90
101
  "abort",
@@ -101,7 +112,12 @@ function buildGraphQLWSExecutor(clientOptionsOrClient) {
101
112
  };
102
113
  Object.defineProperty(executor, disposablestack.DisposableSymbols.asyncDispose, {
103
114
  value: function disposeWS() {
104
- return graphqlWSClient.dispose();
115
+ const clients = [graphqlWSClient, ...clientsByConnectionParams.values()];
116
+ clientsByConnectionParams.clear();
117
+ return Promise.all(clients.map((client) => client.dispose())).then(
118
+ () => {
119
+ }
120
+ );
105
121
  }
106
122
  });
107
123
  return executor;
package/dist/index.js CHANGED
@@ -21,7 +21,8 @@ function isClient(client) {
21
21
  }
22
22
  function buildGraphQLWSExecutor(clientOptionsOrClient) {
23
23
  let graphqlWSClient;
24
- let executorConnectionParams = {};
24
+ const clientsByConnectionParams = /* @__PURE__ */ new Map();
25
+ let getClient = (_extensionsConnectionParams) => graphqlWSClient;
25
26
  let printFn = defaultPrintFn;
26
27
  if (isClient(clientOptionsOrClient)) {
27
28
  graphqlWSClient = clientOptionsOrClient;
@@ -52,20 +53,37 @@ function buildGraphQLWSExecutor(clientOptionsOrClient) {
52
53
  }
53
54
  }
54
55
  } : WebSocket;
55
- graphqlWSClient = createClient({
56
- url: clientOptionsOrClient.url,
57
- webSocketImpl,
58
- lazy: clientOptionsOrClient.lazy !== false,
59
- lazyCloseTimeout: clientOptionsOrClient.lazyCloseTimeout || 0,
60
- connectionParams: () => {
61
- const optionsConnectionParams = (typeof clientOptionsOrClient.connectionParams === "function" ? clientOptionsOrClient.connectionParams() : clientOptionsOrClient.connectionParams) || {};
62
- return Object.assign(optionsConnectionParams, executorConnectionParams);
63
- },
64
- on: clientOptionsOrClient.on
65
- });
66
- if (clientOptionsOrClient.onClient) {
67
- clientOptionsOrClient.onClient(graphqlWSClient);
68
- }
56
+ const clientOptions = clientOptionsOrClient;
57
+ const createWSClient = (extensionsConnectionParams) => {
58
+ const client = createClient({
59
+ url: clientOptions.url,
60
+ webSocketImpl,
61
+ lazy: clientOptions.lazy !== false,
62
+ lazyCloseTimeout: clientOptions.lazyCloseTimeout || 0,
63
+ connectionParams: () => ({
64
+ ...typeof clientOptions.connectionParams === "function" ? clientOptions.connectionParams() : clientOptions.connectionParams,
65
+ ...extensionsConnectionParams
66
+ }),
67
+ on: clientOptions.on
68
+ });
69
+ if (clientOptions.onClient) {
70
+ clientOptions.onClient(client);
71
+ }
72
+ return client;
73
+ };
74
+ graphqlWSClient = createWSClient();
75
+ getClient = (extensionsConnectionParams) => {
76
+ if (!extensionsConnectionParams) {
77
+ return graphqlWSClient;
78
+ }
79
+ const key = JSON.stringify(extensionsConnectionParams);
80
+ let client = clientsByConnectionParams.get(key);
81
+ if (!client) {
82
+ client = createWSClient({ ...extensionsConnectionParams });
83
+ clientsByConnectionParams.set(key, client);
84
+ }
85
+ return client;
86
+ };
69
87
  }
70
88
  const executor = function GraphQLWSExecutor(executionRequest) {
71
89
  const {
@@ -74,15 +92,8 @@ function buildGraphQLWSExecutor(clientOptionsOrClient) {
74
92
  info,
75
93
  signal = info?.signal
76
94
  } = executionRequest;
77
- if (extensions?.["connectionParams"] && typeof extensions?.["connectionParams"] === "object") {
78
- executorConnectionParams = Object.assign(
79
- executorConnectionParams,
80
- extensions["connectionParams"]
81
- );
82
- }
83
- const iterableIterator = graphqlWSClient.iterate(
84
- serializeExecutionRequest({ executionRequest, printFn })
85
- );
95
+ const extensionsConnectionParams = extensions?.["connectionParams"] && typeof extensions?.["connectionParams"] === "object" ? extensions["connectionParams"] : void 0;
96
+ const iterableIterator = getClient(extensionsConnectionParams).iterate(serializeExecutionRequest({ executionRequest, printFn }));
86
97
  if (iterableIterator.return && signal) {
87
98
  signal.addEventListener(
88
99
  "abort",
@@ -99,7 +110,12 @@ function buildGraphQLWSExecutor(clientOptionsOrClient) {
99
110
  };
100
111
  Object.defineProperty(executor, DisposableSymbols.asyncDispose, {
101
112
  value: function disposeWS() {
102
- return graphqlWSClient.dispose();
113
+ const clients = [graphqlWSClient, ...clientsByConnectionParams.values()];
114
+ clientsByConnectionParams.clear();
115
+ return Promise.all(clients.map((client) => client.dispose())).then(
116
+ () => {
117
+ }
118
+ );
103
119
  }
104
120
  });
105
121
  return executor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/executor-graphql-ws",
3
- "version": "3.2.1",
3
+ "version": "3.2.2-alpha-b41f442e4b1825290a8d4d3f94175f882a5f70c9",
4
4
  "type": "module",
5
5
  "description": "A set of utils for faster development of GraphQL tools",
6
6
  "repository": {
@@ -50,7 +50,7 @@
50
50
  "devDependencies": {
51
51
  "@types/ws": "^8.0.0",
52
52
  "graphql": "^16.12.0",
53
- "pkgroll": "2.27.1"
53
+ "pkgroll": "2.29.1"
54
54
  },
55
55
  "sideEffects": false
56
56
  }