@graphql-mesh/transport-ws 0.4.2 → 0.4.3-alpha-74ce70ffa76773d89e7e68c4b984a188ea1d816b

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md ADDED
@@ -0,0 +1,341 @@
1
+ # @graphql-mesh/transport-ws
2
+
3
+ ## 0.4.3-alpha-74ce70ffa76773d89e7e68c4b984a188ea1d816b
4
+
5
+ ### Patch Changes
6
+
7
+ - [#118](https://github.com/graphql-hive/gateway/pull/118) [`16fa46b`](https://github.com/graphql-hive/gateway/commit/16fa46b0e31d1fcbfee977fe02efa5e3eabdb150) Thanks [@ardatan](https://github.com/ardatan)! - dependencies updates:
8
+
9
+ - Updated dependency [`@graphql-tools/executor-graphql-ws@workspace:^` ↗︎](https://www.npmjs.com/package/@graphql-tools/executor-graphql-ws/v/workspace:^) (from `^1.3.0`, in `dependencies`)
10
+
11
+ - Updated dependencies [[`16fa46b`](https://github.com/graphql-hive/gateway/commit/16fa46b0e31d1fcbfee977fe02efa5e3eabdb150)]:
12
+ - @graphql-mesh/transport-common@0.7.14-alpha-74ce70ffa76773d89e7e68c4b984a188ea1d816b
13
+
14
+ ## 0.4.2
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies
19
+ [[`eee53b9`](https://github.com/ardatan/graphql-mesh/commit/eee53b9f455653166c39bca627b3261fbefe4eb7)]:
20
+ - @graphql-mesh/utils@0.102.12
21
+ - @graphql-mesh/transport-common@0.7.13
22
+
23
+ ## 0.4.1
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies
28
+ [[`de41fc2`](https://github.com/ardatan/graphql-mesh/commit/de41fc2932433f8da35b9de9492720e6c8c100af),
29
+ [`de41fc2`](https://github.com/ardatan/graphql-mesh/commit/de41fc2932433f8da35b9de9492720e6c8c100af)]:
30
+ - @graphql-mesh/transport-common@0.7.12
31
+ - @graphql-mesh/utils@0.102.11
32
+
33
+ ## 0.4.0
34
+
35
+ ### Minor Changes
36
+
37
+ - [#7712](https://github.com/ardatan/graphql-mesh/pull/7712)
38
+ [`dc54d58`](https://github.com/ardatan/graphql-mesh/commit/dc54d589afa0d08378565e1153b679397f2853a5)
39
+ Thanks [@EmrysMyrddin](https://github.com/EmrysMyrddin)! - Add support for upstream WebSocket
40
+ subscriptions in Docker and binary distributions.
41
+
42
+ The HTTP headers of the incoming client's request can now be forwarded to the upstream in the
43
+ [WebSocket HTTP upgrade request](https://developer.mozilla.org/en-US/docs/Web/HTTP/Protocol_upgrade_mechanism#upgrading_http1.1_connections):
44
+
45
+ ```ts
46
+ import { defineConfig } from '@graphql-hive/gateway';
47
+
48
+ export const gatewayConfig = defineConfig({
49
+ transportEntries: {
50
+ ['*.http']: {
51
+ options: {
52
+ subscriptions: {
53
+ kind: 'ws',
54
+ location: '/subscriptions',
55
+ headers: [['authentication', '{context.headers.authentication}']],
56
+ },
57
+ },
58
+ },
59
+ },
60
+ });
61
+ ```
62
+
63
+ ### Patch Changes
64
+
65
+ - [#7712](https://github.com/ardatan/graphql-mesh/pull/7712)
66
+ [`dc54d58`](https://github.com/ardatan/graphql-mesh/commit/dc54d589afa0d08378565e1153b679397f2853a5)
67
+ Thanks [@EmrysMyrddin](https://github.com/EmrysMyrddin)! - dependencies updates:
68
+
69
+ - Updated dependency
70
+ [`@graphql-tools/executor-graphql-ws@^1.3.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/executor-graphql-ws/v/1.3.0)
71
+ (from `^1.2.0`, in `dependencies`)
72
+
73
+ - [#7712](https://github.com/ardatan/graphql-mesh/pull/7712)
74
+ [`dc54d58`](https://github.com/ardatan/graphql-mesh/commit/dc54d589afa0d08378565e1153b679397f2853a5)
75
+ Thanks [@EmrysMyrddin](https://github.com/EmrysMyrddin)! - WebSocket connections are now cached
76
+ against the whole `connectionParams` object and forwarded `headers`. The fixes WebSocket
77
+ connection being reused wrongly when `connectionParams.token` is stable while other fields are
78
+ changing.
79
+
80
+ ## 0.3.11
81
+
82
+ ### Patch Changes
83
+
84
+ - Updated dependencies
85
+ [[`997b81c`](https://github.com/ardatan/graphql-mesh/commit/997b81c8a5d28508057806b4f16eecc5b713cf71),
86
+ [`997b81c`](https://github.com/ardatan/graphql-mesh/commit/997b81c8a5d28508057806b4f16eecc5b713cf71)]:
87
+ - @graphql-mesh/transport-common@0.7.11
88
+ - @graphql-mesh/utils@0.102.10
89
+
90
+ ## 0.3.10
91
+
92
+ ### Patch Changes
93
+
94
+ - Updated dependencies
95
+ [[`fad4d27`](https://github.com/ardatan/graphql-mesh/commit/fad4d27bfebb80a374c2041b86ffab509845effe)]:
96
+ - @graphql-mesh/utils@0.102.9
97
+ - @graphql-mesh/transport-common@0.7.10
98
+
99
+ ## 0.3.9
100
+
101
+ ### Patch Changes
102
+
103
+ - Updated dependencies
104
+ [[`518c42c`](https://github.com/ardatan/graphql-mesh/commit/518c42c5a2bee00e224df95c2beb758a28d1323c),
105
+ [`518c42c`](https://github.com/ardatan/graphql-mesh/commit/518c42c5a2bee00e224df95c2beb758a28d1323c)]:
106
+ - @graphql-mesh/transport-common@0.7.9
107
+ - @graphql-mesh/utils@0.102.8
108
+
109
+ ## 0.3.8
110
+
111
+ ### Patch Changes
112
+
113
+ - [#7781](https://github.com/ardatan/graphql-mesh/pull/7781)
114
+ [`50bf472`](https://github.com/ardatan/graphql-mesh/commit/50bf4723657d27dc196d80407bda40c93aa5c9be)
115
+ Thanks [@ardatan](https://github.com/ardatan)! - dependencies updates:
116
+ - Updated dependency
117
+ [`@graphql-tools/utils@^10.5.5` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.5.5)
118
+ (from `^10.5.3`, in `dependencies`)
119
+ - Updated dependencies
120
+ [[`50bf472`](https://github.com/ardatan/graphql-mesh/commit/50bf4723657d27dc196d80407bda40c93aa5c9be),
121
+ [`50bf472`](https://github.com/ardatan/graphql-mesh/commit/50bf4723657d27dc196d80407bda40c93aa5c9be),
122
+ [`50bf472`](https://github.com/ardatan/graphql-mesh/commit/50bf4723657d27dc196d80407bda40c93aa5c9be)]:
123
+ - @graphql-mesh/cross-helpers@0.4.7
124
+ - @graphql-mesh/transport-common@0.7.8
125
+ - @graphql-mesh/utils@0.102.7
126
+
127
+ ## 0.3.7
128
+
129
+ ### Patch Changes
130
+
131
+ - [`340b933`](https://github.com/ardatan/graphql-mesh/commit/340b933afcb9d97064712f09d775d628ad843c42)
132
+ Thanks [@enisdenjo](https://github.com/enisdenjo)! - connectionParams factory function may be
133
+ undefined
134
+
135
+ - Updated dependencies
136
+ [[`bf588d3`](https://github.com/ardatan/graphql-mesh/commit/bf588d372c0078378aaa24beea2da794af7949e6)]:
137
+ - @graphql-mesh/utils@0.102.6
138
+ - @graphql-mesh/transport-common@0.7.7
139
+
140
+ ## 0.3.6
141
+
142
+ ### Patch Changes
143
+
144
+ - Updated dependencies
145
+ [[`3bf14b3`](https://github.com/ardatan/graphql-mesh/commit/3bf14b33ee621cce004a329928b8a04a68218016),
146
+ [`b7f6ebf`](https://github.com/ardatan/graphql-mesh/commit/b7f6ebfa077957c3a1ecad1fed449e972cb09ae0),
147
+ [`0a3e52c`](https://github.com/ardatan/graphql-mesh/commit/0a3e52c2ad2941e7c48f0e80706db41644797c2d)]:
148
+ - @graphql-mesh/utils@0.102.5
149
+ - @graphql-mesh/transport-common@0.7.6
150
+
151
+ ## 0.3.5
152
+
153
+ ### Patch Changes
154
+
155
+ - Updated dependencies
156
+ [[`5146df0`](https://github.com/ardatan/graphql-mesh/commit/5146df0fd3313227d5d7df2beb726ca89e13923f)]:
157
+ - @graphql-mesh/transport-common@0.7.5
158
+
159
+ ## 0.3.4
160
+
161
+ ### Patch Changes
162
+
163
+ - Updated dependencies
164
+ [[`edbc074`](https://github.com/ardatan/graphql-mesh/commit/edbc074523ebc86114bb3342f86b7bcd9268d005),
165
+ [`edbc074`](https://github.com/ardatan/graphql-mesh/commit/edbc074523ebc86114bb3342f86b7bcd9268d005)]:
166
+ - @graphql-mesh/transport-common@0.7.4
167
+ - @graphql-mesh/utils@0.102.4
168
+
169
+ ## 0.3.3
170
+
171
+ ### Patch Changes
172
+
173
+ - Updated dependencies
174
+ [[`14ec31f`](https://github.com/ardatan/graphql-mesh/commit/14ec31f95bc06e9a3d06fae387fc40cc534e01f4),
175
+ [`14ec31f`](https://github.com/ardatan/graphql-mesh/commit/14ec31f95bc06e9a3d06fae387fc40cc534e01f4)]:
176
+ - @graphql-mesh/transport-common@0.7.3
177
+ - @graphql-mesh/utils@0.102.3
178
+
179
+ ## 0.3.2
180
+
181
+ ### Patch Changes
182
+
183
+ - Updated dependencies
184
+ [[`5d95aad`](https://github.com/ardatan/graphql-mesh/commit/5d95aad185448e8e3a004a08e364f98ee9bbee2a)]:
185
+ - @graphql-mesh/utils@0.102.2
186
+ - @graphql-mesh/transport-common@0.7.2
187
+
188
+ ## 0.3.1
189
+
190
+ ### Patch Changes
191
+
192
+ - Updated dependencies
193
+ [[`e49a7e6`](https://github.com/ardatan/graphql-mesh/commit/e49a7e69475b652a53a0f289a44247e8b7ea96de),
194
+ [`60bfc22`](https://github.com/ardatan/graphql-mesh/commit/60bfc2240108af0a599a66451517a146cace879d)]:
195
+ - @graphql-mesh/utils@0.102.1
196
+ - @graphql-mesh/transport-common@0.7.1
197
+
198
+ ## 0.3.0
199
+
200
+ ### Patch Changes
201
+
202
+ - Updated dependencies
203
+ [[`13fa835`](https://github.com/ardatan/graphql-mesh/commit/13fa835036c3671305fc831fa236f110c33d9965)]:
204
+ - @graphql-mesh/string-interpolation@0.5.6
205
+ - @graphql-mesh/utils@0.102.0
206
+ - @graphql-mesh/transport-common@0.7.0
207
+
208
+ ## 0.2.2
209
+
210
+ ### Patch Changes
211
+
212
+ - [#7518](https://github.com/ardatan/graphql-mesh/pull/7518)
213
+ [`b0cdc83`](https://github.com/ardatan/graphql-mesh/commit/b0cdc839699a1dd90d125289b49b75f703cbb18e)
214
+ Thanks [@enisdenjo](https://github.com/enisdenjo)! - dependencies updates:
215
+ - Updated dependency
216
+ [`@graphql-mesh/transport-common@^0.6.1` ↗︎](https://www.npmjs.com/package/@graphql-mesh/transport-common/v/0.6.1)
217
+ (from `^0.6.0`, in `dependencies`)
218
+
219
+ ## 0.2.1
220
+
221
+ ### Patch Changes
222
+
223
+ - [#7516](https://github.com/ardatan/graphql-mesh/pull/7516)
224
+ [`67e1062`](https://github.com/ardatan/graphql-mesh/commit/67e10629c70ec553234c1ffc99af4b89ddb31985)
225
+ Thanks [@enisdenjo](https://github.com/enisdenjo)! - Transport's kind doesn't need to be typed
226
+
227
+ - Updated dependencies
228
+ [[`67e1062`](https://github.com/ardatan/graphql-mesh/commit/67e10629c70ec553234c1ffc99af4b89ddb31985)]:
229
+ - @graphql-mesh/transport-common@0.6.1
230
+
231
+ ## 0.2.0
232
+
233
+ ### Patch Changes
234
+
235
+ - [#7497](https://github.com/ardatan/graphql-mesh/pull/7497)
236
+ [`d784488`](https://github.com/ardatan/graphql-mesh/commit/d784488dcf04b3b0bf32f386baf8b48e1f20d27e)
237
+ Thanks [@ardatan](https://github.com/ardatan)! - dependencies updates:
238
+
239
+ - Updated dependency
240
+ [`@graphql-tools/utils@^10.5.2` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.5.2)
241
+ (from `^10.3.4`, in `dependencies`)
242
+
243
+ - [#7512](https://github.com/ardatan/graphql-mesh/pull/7512)
244
+ [`190e9ec`](https://github.com/ardatan/graphql-mesh/commit/190e9ece9bc050a0564f3b5292ab5229e63d40a6)
245
+ Thanks [@ardatan](https://github.com/ardatan)! - dependencies updates:
246
+ - Updated dependency
247
+ [`@graphql-tools/utils@^10.5.3` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.5.3)
248
+ (from `^10.5.2`, in `dependencies`)
249
+ - Updated dependencies
250
+ [[`d784488`](https://github.com/ardatan/graphql-mesh/commit/d784488dcf04b3b0bf32f386baf8b48e1f20d27e),
251
+ [`190e9ec`](https://github.com/ardatan/graphql-mesh/commit/190e9ece9bc050a0564f3b5292ab5229e63d40a6),
252
+ [`d784488`](https://github.com/ardatan/graphql-mesh/commit/d784488dcf04b3b0bf32f386baf8b48e1f20d27e),
253
+ [`190e9ec`](https://github.com/ardatan/graphql-mesh/commit/190e9ece9bc050a0564f3b5292ab5229e63d40a6),
254
+ [`d784488`](https://github.com/ardatan/graphql-mesh/commit/d784488dcf04b3b0bf32f386baf8b48e1f20d27e),
255
+ [`190e9ec`](https://github.com/ardatan/graphql-mesh/commit/190e9ece9bc050a0564f3b5292ab5229e63d40a6),
256
+ [`d784488`](https://github.com/ardatan/graphql-mesh/commit/d784488dcf04b3b0bf32f386baf8b48e1f20d27e)]:
257
+ - @graphql-mesh/cross-helpers@0.4.6
258
+ - @graphql-mesh/transport-common@0.6.0
259
+ - @graphql-mesh/utils@0.101.0
260
+
261
+ ## 0.1.0
262
+
263
+ ### Patch Changes
264
+
265
+ - [#7477](https://github.com/ardatan/graphql-mesh/pull/7477)
266
+ [`c06a048`](https://github.com/ardatan/graphql-mesh/commit/c06a0482e7431683f0b75fde3aebbb97aca00c4c)
267
+ Thanks [@ardatan](https://github.com/ardatan)! - dependencies updates:
268
+ - Updated dependency
269
+ [`@graphql-tools/utils@^10.3.4` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.3.4)
270
+ (from `^10.2.3`, in `dependencies`)
271
+ - Updated dependencies
272
+ [[`c06a048`](https://github.com/ardatan/graphql-mesh/commit/c06a0482e7431683f0b75fde3aebbb97aca00c4c),
273
+ [`c06a048`](https://github.com/ardatan/graphql-mesh/commit/c06a0482e7431683f0b75fde3aebbb97aca00c4c),
274
+ [`c06a048`](https://github.com/ardatan/graphql-mesh/commit/c06a0482e7431683f0b75fde3aebbb97aca00c4c),
275
+ [`a324c5e`](https://github.com/ardatan/graphql-mesh/commit/a324c5ef300c25dcfa265f3457453b50af0b83e7),
276
+ [`4d1eb28`](https://github.com/ardatan/graphql-mesh/commit/4d1eb285c2b703c5f80473ad0f316004306fac7f),
277
+ [`a324c5e`](https://github.com/ardatan/graphql-mesh/commit/a324c5ef300c25dcfa265f3457453b50af0b83e7)]:
278
+ - @graphql-mesh/cross-helpers@0.4.5
279
+ - @graphql-mesh/transport-common@0.5.0
280
+ - @graphql-mesh/utils@0.100.0
281
+
282
+ ## 0.0.6
283
+
284
+ ### Patch Changes
285
+
286
+ - Updated dependencies []:
287
+ - @graphql-mesh/utils@0.99.7
288
+ - @graphql-mesh/transport-common@0.4.7
289
+
290
+ ## 0.0.5
291
+
292
+ ### Patch Changes
293
+
294
+ - Updated dependencies
295
+ [[`6c67e77`](https://github.com/ardatan/graphql-mesh/commit/6c67e77d3c308615a733577293ecb6dd55793aeb),
296
+ [`6c67e77`](https://github.com/ardatan/graphql-mesh/commit/6c67e77d3c308615a733577293ecb6dd55793aeb),
297
+ [`6c67e77`](https://github.com/ardatan/graphql-mesh/commit/6c67e77d3c308615a733577293ecb6dd55793aeb),
298
+ [`6c67e77`](https://github.com/ardatan/graphql-mesh/commit/6c67e77d3c308615a733577293ecb6dd55793aeb)]:
299
+ - @graphql-mesh/transport-common@0.4.6
300
+ - @graphql-mesh/utils@0.99.6
301
+
302
+ ## 0.0.4
303
+
304
+ ### Patch Changes
305
+
306
+ - [#7401](https://github.com/ardatan/graphql-mesh/pull/7401)
307
+ [`33c23e8`](https://github.com/ardatan/graphql-mesh/commit/33c23e83a60328df806a8adc8d262a0c6de7e5a4)
308
+ Thanks [@ardatan](https://github.com/ardatan)! - dependencies updates:
309
+ - Added dependency
310
+ [`@graphql-mesh/utils@^0.99.4` ↗︎](https://www.npmjs.com/package/@graphql-mesh/utils/v/0.99.4)
311
+ (to `dependencies`)
312
+ - Updated dependencies
313
+ [[`33c23e8`](https://github.com/ardatan/graphql-mesh/commit/33c23e83a60328df806a8adc8d262a0c6de7e5a4)]:
314
+ - @graphql-mesh/utils@0.99.5
315
+ - @graphql-mesh/transport-common@0.4.5
316
+
317
+ ## 0.0.3
318
+
319
+ ### Patch Changes
320
+
321
+ - Updated dependencies []:
322
+ - @graphql-mesh/transport-common@0.4.4
323
+
324
+ ## 0.0.2
325
+
326
+ ### Patch Changes
327
+
328
+ - Updated dependencies []:
329
+ - @graphql-mesh/transport-common@0.4.3
330
+
331
+ ## 0.0.1
332
+
333
+ ### Patch Changes
334
+
335
+ - Updated dependencies
336
+ [[`b01f3ea`](https://github.com/ardatan/graphql-mesh/commit/b01f3eabdc42d8905e8d586a4845e8394c094033),
337
+ [`0bdc18d`](https://github.com/ardatan/graphql-mesh/commit/0bdc18df3d150a61abf987b8829934ed4ca02eed),
338
+ [`4bc495c`](https://github.com/ardatan/graphql-mesh/commit/4bc495c03493f18c85e11f3f5fb54b3c35d16d8e),
339
+ [`345a814`](https://github.com/ardatan/graphql-mesh/commit/345a81490f5201f6ee2f378b1b9d83c5881c9730)]:
340
+ - @graphql-mesh/string-interpolation@0.5.5
341
+ - @graphql-mesh/transport-common@0.4.2
package/dist/index.cjs ADDED
@@ -0,0 +1,101 @@
1
+ 'use strict';
2
+
3
+ var crossHelpers = require('@graphql-mesh/cross-helpers');
4
+ var stringInterpolation = require('@graphql-mesh/string-interpolation');
5
+ var transportCommon = require('@graphql-mesh/transport-common');
6
+ var utils = require('@graphql-mesh/utils');
7
+ var executorGraphqlWs = require('@graphql-tools/executor-graphql-ws');
8
+
9
+ function switchProtocols(url) {
10
+ if (url.startsWith("https://")) {
11
+ return url.replace("https://", "wss://");
12
+ }
13
+ if (url.startsWith("http://")) {
14
+ return url.replace("http://", "ws://");
15
+ }
16
+ return url;
17
+ }
18
+ var index = {
19
+ getSubgraphExecutor({ transportEntry, logger }) {
20
+ const wsExecutorMap = /* @__PURE__ */ new Map();
21
+ if (!transportEntry.location) {
22
+ throw new Error(
23
+ "WS Transport: location is required in the transport entry"
24
+ );
25
+ }
26
+ const wsUrl = switchProtocols(transportEntry.location);
27
+ const connectionParamsFactory = transportEntry.options?.connectionParams ? stringInterpolation.getInterpolatedHeadersFactory(transportEntry.options.connectionParams) : void 0;
28
+ const headersFactory = transportEntry.headers ? stringInterpolation.getInterpolatedHeadersFactory(
29
+ Object.fromEntries(transportEntry.headers)
30
+ ) : void 0;
31
+ const mergedExecutor = function mergedExecutor2(execReq) {
32
+ const connectionParams = connectionParamsFactory?.({
33
+ env: crossHelpers.process.env,
34
+ root: execReq.rootValue,
35
+ context: execReq.context,
36
+ info: execReq.info
37
+ });
38
+ const headers = headersFactory?.({
39
+ env: crossHelpers.process.env,
40
+ root: execReq.rootValue,
41
+ context: execReq.context,
42
+ info: execReq.info
43
+ });
44
+ const hash = JSON.stringify({ wsUrl, connectionParams, headers });
45
+ let wsExecutor = wsExecutorMap.get(hash);
46
+ if (!wsExecutor) {
47
+ const executorLogger = logger?.child("GraphQL WS").child(hash);
48
+ wsExecutor = executorGraphqlWs.buildGraphQLWSExecutor({
49
+ url: wsUrl,
50
+ lazy: true,
51
+ lazyCloseTimeout: 3e3,
52
+ ...transportEntry.options,
53
+ headers,
54
+ connectionParams,
55
+ on: {
56
+ connecting(isRetry) {
57
+ executorLogger?.debug("connecting", { isRetry });
58
+ },
59
+ opened(socket) {
60
+ executorLogger?.debug("opened", { socket });
61
+ },
62
+ connected(socket, payload) {
63
+ executorLogger?.debug("connected", { socket, payload });
64
+ },
65
+ ping(received, payload) {
66
+ executorLogger?.debug("ping", { received, payload });
67
+ },
68
+ pong(received, payload) {
69
+ executorLogger?.debug("pong", { received, payload });
70
+ },
71
+ message(message) {
72
+ executorLogger?.debug("message", { message });
73
+ },
74
+ closed(event) {
75
+ executorLogger?.debug("closed", { event });
76
+ wsExecutorMap.delete(hash);
77
+ },
78
+ error(error) {
79
+ executorLogger?.debug("error", { error });
80
+ }
81
+ },
82
+ // @ts-expect-error wrong typings for print fn
83
+ print: transportCommon.defaultPrintFn
84
+ });
85
+ wsExecutorMap.set(hash, wsExecutor);
86
+ }
87
+ return wsExecutor(execReq);
88
+ };
89
+ return utils.makeAsyncDisposable(
90
+ mergedExecutor,
91
+ () => Promise.all(
92
+ Array.from(wsExecutorMap.values()).map(
93
+ (executor) => utils.isDisposable(executor) && utils.dispose(executor)
94
+ )
95
+ ).then(() => {
96
+ })
97
+ );
98
+ }
99
+ };
100
+
101
+ module.exports = index;
@@ -0,0 +1,12 @@
1
+ import * as _graphql_mesh_transport_common from '@graphql-mesh/transport-common';
2
+ import { DisposableExecutor } from '@graphql-mesh/transport-common';
3
+ import { ClientOptions } from 'graphql-ws';
4
+
5
+ type WSTransportOptions = Omit<ClientOptions, 'url' | 'on' | 'connectionParams'> & {
6
+ connectionParams?: Record<string, string>;
7
+ };
8
+ declare const _default: {
9
+ getSubgraphExecutor({ transportEntry, logger }: _graphql_mesh_transport_common.TransportGetSubgraphExecutorOptions<WSTransportOptions>): DisposableExecutor & AsyncDisposable;
10
+ };
11
+
12
+ export { type WSTransportOptions, _default as default };
@@ -0,0 +1,12 @@
1
+ import * as _graphql_mesh_transport_common from '@graphql-mesh/transport-common';
2
+ import { DisposableExecutor } from '@graphql-mesh/transport-common';
3
+ import { ClientOptions } from 'graphql-ws';
4
+
5
+ type WSTransportOptions = Omit<ClientOptions, 'url' | 'on' | 'connectionParams'> & {
6
+ connectionParams?: Record<string, string>;
7
+ };
8
+ declare const _default: {
9
+ getSubgraphExecutor({ transportEntry, logger }: _graphql_mesh_transport_common.TransportGetSubgraphExecutorOptions<WSTransportOptions>): DisposableExecutor & AsyncDisposable;
10
+ };
11
+
12
+ export { type WSTransportOptions, _default as default };
package/dist/index.js ADDED
@@ -0,0 +1,99 @@
1
+ import { process } from '@graphql-mesh/cross-helpers';
2
+ import { getInterpolatedHeadersFactory } from '@graphql-mesh/string-interpolation';
3
+ import { defaultPrintFn } from '@graphql-mesh/transport-common';
4
+ import { makeAsyncDisposable, isDisposable, dispose } from '@graphql-mesh/utils';
5
+ import { buildGraphQLWSExecutor } from '@graphql-tools/executor-graphql-ws';
6
+
7
+ function switchProtocols(url) {
8
+ if (url.startsWith("https://")) {
9
+ return url.replace("https://", "wss://");
10
+ }
11
+ if (url.startsWith("http://")) {
12
+ return url.replace("http://", "ws://");
13
+ }
14
+ return url;
15
+ }
16
+ var index = {
17
+ getSubgraphExecutor({ transportEntry, logger }) {
18
+ const wsExecutorMap = /* @__PURE__ */ new Map();
19
+ if (!transportEntry.location) {
20
+ throw new Error(
21
+ "WS Transport: location is required in the transport entry"
22
+ );
23
+ }
24
+ const wsUrl = switchProtocols(transportEntry.location);
25
+ const connectionParamsFactory = transportEntry.options?.connectionParams ? getInterpolatedHeadersFactory(transportEntry.options.connectionParams) : void 0;
26
+ const headersFactory = transportEntry.headers ? getInterpolatedHeadersFactory(
27
+ Object.fromEntries(transportEntry.headers)
28
+ ) : void 0;
29
+ const mergedExecutor = function mergedExecutor2(execReq) {
30
+ const connectionParams = connectionParamsFactory?.({
31
+ env: process.env,
32
+ root: execReq.rootValue,
33
+ context: execReq.context,
34
+ info: execReq.info
35
+ });
36
+ const headers = headersFactory?.({
37
+ env: process.env,
38
+ root: execReq.rootValue,
39
+ context: execReq.context,
40
+ info: execReq.info
41
+ });
42
+ const hash = JSON.stringify({ wsUrl, connectionParams, headers });
43
+ let wsExecutor = wsExecutorMap.get(hash);
44
+ if (!wsExecutor) {
45
+ const executorLogger = logger?.child("GraphQL WS").child(hash);
46
+ wsExecutor = buildGraphQLWSExecutor({
47
+ url: wsUrl,
48
+ lazy: true,
49
+ lazyCloseTimeout: 3e3,
50
+ ...transportEntry.options,
51
+ headers,
52
+ connectionParams,
53
+ on: {
54
+ connecting(isRetry) {
55
+ executorLogger?.debug("connecting", { isRetry });
56
+ },
57
+ opened(socket) {
58
+ executorLogger?.debug("opened", { socket });
59
+ },
60
+ connected(socket, payload) {
61
+ executorLogger?.debug("connected", { socket, payload });
62
+ },
63
+ ping(received, payload) {
64
+ executorLogger?.debug("ping", { received, payload });
65
+ },
66
+ pong(received, payload) {
67
+ executorLogger?.debug("pong", { received, payload });
68
+ },
69
+ message(message) {
70
+ executorLogger?.debug("message", { message });
71
+ },
72
+ closed(event) {
73
+ executorLogger?.debug("closed", { event });
74
+ wsExecutorMap.delete(hash);
75
+ },
76
+ error(error) {
77
+ executorLogger?.debug("error", { error });
78
+ }
79
+ },
80
+ // @ts-expect-error wrong typings for print fn
81
+ print: defaultPrintFn
82
+ });
83
+ wsExecutorMap.set(hash, wsExecutor);
84
+ }
85
+ return wsExecutor(execReq);
86
+ };
87
+ return makeAsyncDisposable(
88
+ mergedExecutor,
89
+ () => Promise.all(
90
+ Array.from(wsExecutorMap.values()).map(
91
+ (executor) => isDisposable(executor) && dispose(executor)
92
+ )
93
+ ).then(() => {
94
+ })
95
+ );
96
+ }
97
+ };
98
+
99
+ export { index as default };
package/package.json CHANGED
@@ -1,52 +1,63 @@
1
1
  {
2
2
  "name": "@graphql-mesh/transport-ws",
3
- "version": "0.4.2",
4
- "sideEffects": false,
5
- "peerDependencies": {
6
- "graphql": "*",
7
- "tslib": "^2.4.0"
8
- },
9
- "dependencies": {
10
- "@graphql-mesh/cross-helpers": "0.4.7",
11
- "@graphql-mesh/string-interpolation": "^0.5.6",
12
- "@graphql-mesh/transport-common": "^0.7.13",
13
- "@graphql-mesh/utils": "^0.102.12",
14
- "@graphql-tools/executor-graphql-ws": "^1.3.0",
15
- "@graphql-tools/utils": "^10.5.5",
16
- "graphql-ws": "^5.16.0",
17
- "ws": "^8.18.0"
18
- },
3
+ "version": "0.4.3-alpha-74ce70ffa76773d89e7e68c4b984a188ea1d816b",
4
+ "type": "module",
19
5
  "repository": {
20
6
  "type": "git",
21
- "url": "ardatan/graphql-mesh",
7
+ "url": "git+https://github.com/graphql-hive/gateway.git",
22
8
  "directory": "packages/transports/ws"
23
9
  },
10
+ "author": {
11
+ "email": "contact@the-guild.dev",
12
+ "name": "The Guild",
13
+ "url": "https://the-guild.dev"
14
+ },
24
15
  "license": "MIT",
25
16
  "engines": {
26
- "node": ">=16.0.0"
27
- },
28
- "main": "cjs/index.js",
29
- "module": "esm/index.js",
30
- "typings": "typings/index.d.ts",
31
- "typescript": {
32
- "definition": "typings/index.d.ts"
17
+ "node": ">=18.0.0"
33
18
  },
34
- "type": "module",
19
+ "main": "./dist/index.js",
35
20
  "exports": {
36
21
  ".": {
37
22
  "require": {
38
- "types": "./typings/index.d.cts",
39
- "default": "./cjs/index.js"
23
+ "types": "./dist/index.d.cts",
24
+ "default": "./dist/index.cjs"
40
25
  },
41
26
  "import": {
42
- "types": "./typings/index.d.ts",
43
- "default": "./esm/index.js"
44
- },
45
- "default": {
46
- "types": "./typings/index.d.ts",
47
- "default": "./esm/index.js"
27
+ "types": "./dist/index.d.ts",
28
+ "default": "./dist/index.js"
48
29
  }
49
30
  },
50
31
  "./package.json": "./package.json"
51
- }
32
+ },
33
+ "types": "./dist/index.d.ts",
34
+ "files": [
35
+ "dist"
36
+ ],
37
+ "scripts": {
38
+ "build": "pkgroll --clean-dist",
39
+ "prepack": "yarn build"
40
+ },
41
+ "peerDependencies": {
42
+ "graphql": "^15.9.0 || ^16.9.0"
43
+ },
44
+ "dependencies": {
45
+ "@graphql-mesh/cross-helpers": "0.4.7",
46
+ "@graphql-mesh/string-interpolation": "^0.5.6",
47
+ "@graphql-mesh/transport-common": "^0.7.14-alpha-74ce70ffa76773d89e7e68c4b984a188ea1d816b",
48
+ "@graphql-mesh/types": "^0.102.12",
49
+ "@graphql-mesh/utils": "^0.102.12",
50
+ "@graphql-tools/executor-graphql-ws": "^1.3.2",
51
+ "@graphql-tools/utils": "^10.5.5",
52
+ "graphql-ws": "^5.16.0",
53
+ "tslib": "^2.4.0",
54
+ "ws": "^8.18.0"
55
+ },
56
+ "devDependencies": {
57
+ "@graphql-mesh/store": "^0.102.12",
58
+ "@types/ws": "^8",
59
+ "graphql": "^16.9.0",
60
+ "pkgroll": "2.5.1"
61
+ },
62
+ "sideEffects": false
52
63
  }
package/cjs/index.js DELETED
@@ -1,88 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
4
- const string_interpolation_1 = require("@graphql-mesh/string-interpolation");
5
- const transport_common_1 = require("@graphql-mesh/transport-common");
6
- const utils_1 = require("@graphql-mesh/utils");
7
- const executor_graphql_ws_1 = require("@graphql-tools/executor-graphql-ws");
8
- function switchProtocols(url) {
9
- if (url.startsWith('https://')) {
10
- return url.replace('https://', 'wss://');
11
- }
12
- if (url.startsWith('http://')) {
13
- return url.replace('http://', 'ws://');
14
- }
15
- return url;
16
- }
17
- exports.default = {
18
- getSubgraphExecutor({ transportEntry, logger }) {
19
- const wsExecutorMap = new Map();
20
- const wsUrl = switchProtocols(transportEntry.location);
21
- const connectionParamsFactory = transportEntry.options?.connectionParams
22
- ? (0, string_interpolation_1.getInterpolatedHeadersFactory)(transportEntry.options.connectionParams)
23
- : undefined;
24
- const headersFactory = transportEntry.headers
25
- ? (0, string_interpolation_1.getInterpolatedHeadersFactory)(Object.fromEntries(transportEntry.headers))
26
- : undefined;
27
- const mergedExecutor = function mergedExecutor(execReq) {
28
- const connectionParams = connectionParamsFactory?.({
29
- env: cross_helpers_1.process.env,
30
- root: execReq.rootValue,
31
- context: execReq.context,
32
- info: execReq.info,
33
- });
34
- const headers = headersFactory?.({
35
- env: cross_helpers_1.process.env,
36
- root: execReq.rootValue,
37
- context: execReq.context,
38
- info: execReq.info,
39
- });
40
- const hash = JSON.stringify({ wsUrl, connectionParams, headers });
41
- let wsExecutor = wsExecutorMap.get(hash);
42
- if (!wsExecutor) {
43
- const executorLogger = logger.child('GraphQL WS').child(hash);
44
- wsExecutor = (0, executor_graphql_ws_1.buildGraphQLWSExecutor)({
45
- url: wsUrl,
46
- lazy: true,
47
- lazyCloseTimeout: 3_000,
48
- ...transportEntry.options,
49
- headers,
50
- connectionParams,
51
- on: {
52
- connecting(isRetry) {
53
- executorLogger.debug('connecting', { isRetry });
54
- },
55
- opened(socket) {
56
- executorLogger.debug('opened', { socket });
57
- },
58
- connected(socket, payload) {
59
- executorLogger.debug('connected', { socket, payload });
60
- },
61
- ping(received, payload) {
62
- executorLogger.debug('ping', { received, payload });
63
- },
64
- pong(received, payload) {
65
- executorLogger.debug('pong', { received, payload });
66
- },
67
- message(message) {
68
- executorLogger.debug('message', { message });
69
- },
70
- closed(event) {
71
- executorLogger.debug('closed', { event });
72
- // no subscriptions and the lazy close timeout has passed - remove the client
73
- wsExecutorMap.delete(hash);
74
- },
75
- error(error) {
76
- executorLogger.debug('error', { error });
77
- },
78
- },
79
- // @ts-expect-error wrong typings for print fn
80
- print: transport_common_1.defaultPrintFn,
81
- });
82
- wsExecutorMap.set(hash, wsExecutor);
83
- }
84
- return wsExecutor(execReq);
85
- };
86
- return (0, utils_1.makeAsyncDisposable)(mergedExecutor, () => Promise.all(Array.from(wsExecutorMap.values()).map(executor => (0, utils_1.isDisposable)(executor) && (0, utils_1.dispose)(executor))).then(() => { }));
87
- },
88
- };
package/cjs/package.json DELETED
@@ -1 +0,0 @@
1
- {"type":"commonjs"}
package/esm/index.js DELETED
@@ -1,86 +0,0 @@
1
- import { process } from '@graphql-mesh/cross-helpers';
2
- import { getInterpolatedHeadersFactory } from '@graphql-mesh/string-interpolation';
3
- import { defaultPrintFn, } from '@graphql-mesh/transport-common';
4
- import { dispose, isDisposable, makeAsyncDisposable } from '@graphql-mesh/utils';
5
- import { buildGraphQLWSExecutor } from '@graphql-tools/executor-graphql-ws';
6
- function switchProtocols(url) {
7
- if (url.startsWith('https://')) {
8
- return url.replace('https://', 'wss://');
9
- }
10
- if (url.startsWith('http://')) {
11
- return url.replace('http://', 'ws://');
12
- }
13
- return url;
14
- }
15
- export default {
16
- getSubgraphExecutor({ transportEntry, logger }) {
17
- const wsExecutorMap = new Map();
18
- const wsUrl = switchProtocols(transportEntry.location);
19
- const connectionParamsFactory = transportEntry.options?.connectionParams
20
- ? getInterpolatedHeadersFactory(transportEntry.options.connectionParams)
21
- : undefined;
22
- const headersFactory = transportEntry.headers
23
- ? getInterpolatedHeadersFactory(Object.fromEntries(transportEntry.headers))
24
- : undefined;
25
- const mergedExecutor = function mergedExecutor(execReq) {
26
- const connectionParams = connectionParamsFactory?.({
27
- env: process.env,
28
- root: execReq.rootValue,
29
- context: execReq.context,
30
- info: execReq.info,
31
- });
32
- const headers = headersFactory?.({
33
- env: process.env,
34
- root: execReq.rootValue,
35
- context: execReq.context,
36
- info: execReq.info,
37
- });
38
- const hash = JSON.stringify({ wsUrl, connectionParams, headers });
39
- let wsExecutor = wsExecutorMap.get(hash);
40
- if (!wsExecutor) {
41
- const executorLogger = logger.child('GraphQL WS').child(hash);
42
- wsExecutor = buildGraphQLWSExecutor({
43
- url: wsUrl,
44
- lazy: true,
45
- lazyCloseTimeout: 3_000,
46
- ...transportEntry.options,
47
- headers,
48
- connectionParams,
49
- on: {
50
- connecting(isRetry) {
51
- executorLogger.debug('connecting', { isRetry });
52
- },
53
- opened(socket) {
54
- executorLogger.debug('opened', { socket });
55
- },
56
- connected(socket, payload) {
57
- executorLogger.debug('connected', { socket, payload });
58
- },
59
- ping(received, payload) {
60
- executorLogger.debug('ping', { received, payload });
61
- },
62
- pong(received, payload) {
63
- executorLogger.debug('pong', { received, payload });
64
- },
65
- message(message) {
66
- executorLogger.debug('message', { message });
67
- },
68
- closed(event) {
69
- executorLogger.debug('closed', { event });
70
- // no subscriptions and the lazy close timeout has passed - remove the client
71
- wsExecutorMap.delete(hash);
72
- },
73
- error(error) {
74
- executorLogger.debug('error', { error });
75
- },
76
- },
77
- // @ts-expect-error wrong typings for print fn
78
- print: defaultPrintFn,
79
- });
80
- wsExecutorMap.set(hash, wsExecutor);
81
- }
82
- return wsExecutor(execReq);
83
- };
84
- return makeAsyncDisposable(mergedExecutor, () => Promise.all(Array.from(wsExecutorMap.values()).map(executor => isDisposable(executor) && dispose(executor))).then(() => { }));
85
- },
86
- };
@@ -1,9 +0,0 @@
1
- import type { ClientOptions } from 'graphql-ws';
2
- import { type DisposableExecutor } from '@graphql-mesh/transport-common';
3
- export type WSTransportOptions = Omit<ClientOptions, 'url' | 'on' | 'connectionParams'> & {
4
- connectionParams?: Record<string, string>;
5
- };
6
- declare const _default: {
7
- getSubgraphExecutor({ transportEntry, logger }: import("@graphql-mesh/transport-common").TransportGetSubgraphExecutorOptions<WSTransportOptions>): DisposableExecutor & AsyncDisposable;
8
- };
9
- export default _default;
@@ -1,9 +0,0 @@
1
- import type { ClientOptions } from 'graphql-ws';
2
- import { type DisposableExecutor } from '@graphql-mesh/transport-common';
3
- export type WSTransportOptions = Omit<ClientOptions, 'url' | 'on' | 'connectionParams'> & {
4
- connectionParams?: Record<string, string>;
5
- };
6
- declare const _default: {
7
- getSubgraphExecutor({ transportEntry, logger }: import("@graphql-mesh/transport-common").TransportGetSubgraphExecutorOptions<WSTransportOptions>): DisposableExecutor & AsyncDisposable;
8
- };
9
- export default _default;