@graphql-tools/executor-graphql-ws 1.3.2 → 1.3.3-alpha-63d80f9d08b5d8448f4bfb8b04aeff28b977dec8

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 ADDED
@@ -0,0 +1,264 @@
1
+ # @graphql-tools/executor-graphql-ws
2
+
3
+ ## 1.3.3-alpha-63d80f9d08b5d8448f4bfb8b04aeff28b977dec8
4
+
5
+ ### Patch Changes
6
+
7
+ - [#164](https://github.com/graphql-hive/gateway/pull/164) [`310613d`](https://github.com/graphql-hive/gateway/commit/310613d68d1df3e2bceafbd0730084a4c83527bf) Thanks [@ardatan](https://github.com/ardatan)! - dependencies updates:
8
+
9
+ - Updated dependency [`@graphql-tools/utils@^10.6.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.6.0) (from `^10.5.6`, in `dependencies`)
10
+
11
+ ## 1.3.2
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies
16
+ [[`dc5043b`](https://github.com/ardatan/graphql-tools/commit/dc5043bb7c9afaca907c242eb6bf65e8019d79c4)]:
17
+ - @graphql-tools/utils@10.5.6
18
+
19
+ ## 1.3.1
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies
24
+ [[`cf2ce5e`](https://github.com/ardatan/graphql-tools/commit/cf2ce5ed4773087cc324599f2812f4fb91398b21)]:
25
+ - @graphql-tools/utils@10.5.5
26
+
27
+ ## 1.3.0
28
+
29
+ ### Minor Changes
30
+
31
+ - [#6540](https://github.com/ardatan/graphql-tools/pull/6540)
32
+ [`1e085bd`](https://github.com/ardatan/graphql-tools/commit/1e085bd8516a692e91afe3f1b95b9f5740485693)
33
+ Thanks [@EmrysMyrddin](https://github.com/EmrysMyrddin)! - Allow to configure headers of the
34
+ WebSocket sent with the upgrade request.
35
+
36
+ ## 1.2.1
37
+
38
+ ### Patch Changes
39
+
40
+ - [#6536](https://github.com/ardatan/graphql-tools/pull/6536)
41
+ [`3facde0`](https://github.com/ardatan/graphql-tools/commit/3facde02724add648a00feafaaee6a76a443d25d)
42
+ Thanks [@EmrysMyrddin](https://github.com/EmrysMyrddin)! - `webSocketImpl` and `lazy` options were
43
+ ignored and overriden by default values. This is no longer the case and it's now possible to
44
+ change the `WebSocket` implementation.
45
+
46
+ ## 1.2.0
47
+
48
+ ### Minor Changes
49
+
50
+ - [#6323](https://github.com/ardatan/graphql-tools/pull/6323)
51
+ [`cacf20f`](https://github.com/ardatan/graphql-tools/commit/cacf20f8dbe4ec5dce0d5fd87e37cf69ef9b177e)
52
+ Thanks [@ardatan](https://github.com/ardatan)! - Implement Symbol.dispose or Symbol.asyncDispose
53
+ to make \`Executor\`s \`Disposable\`
54
+
55
+ ### Patch Changes
56
+
57
+ - Updated dependencies
58
+ [[`cacf20f`](https://github.com/ardatan/graphql-tools/commit/cacf20f8dbe4ec5dce0d5fd87e37cf69ef9b177e)]:
59
+ - @graphql-tools/utils@10.3.0
60
+
61
+ ## 1.1.2
62
+
63
+ ### Patch Changes
64
+
65
+ - [#5913](https://github.com/ardatan/graphql-tools/pull/5913)
66
+ [`83c0af0`](https://github.com/ardatan/graphql-tools/commit/83c0af0713ff2ce55ccfb97a1810ecfecfeab703)
67
+ Thanks [@enisdenjo](https://github.com/enisdenjo)! - dependencies updates:
68
+ - Updated dependency
69
+ [`@graphql-tools/utils@^10.0.13` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.0.13)
70
+ (from `^10.0.2`, in `dependencies`)
71
+
72
+ ## 1.1.1
73
+
74
+ ### Patch Changes
75
+
76
+ - [#5666](https://github.com/ardatan/graphql-tools/pull/5666)
77
+ [`6269314d`](https://github.com/ardatan/graphql-tools/commit/6269314dfe2ae7b9074096a2831e39c9ee17be0a)
78
+ Thanks [@ThomasMoritz](https://github.com/ThomasMoritz)! - changed the order how the configuration
79
+ is given into the graphql-wsclient and prevent the overwriting of the parameters
80
+
81
+ ## 1.1.0
82
+
83
+ ### Minor Changes
84
+
85
+ - [#4781](https://github.com/ardatan/graphql-tools/pull/4781)
86
+ [`104921ff`](https://github.com/ardatan/graphql-tools/commit/104921ffc066bde737d4cb36a3bbd1b3b2ad4094)
87
+ Thanks [@enisdenjo](https://github.com/enisdenjo)! - Read and use `connectionParams` from
88
+ operation extensions
89
+
90
+ ## 1.0.2
91
+
92
+ ### Patch Changes
93
+
94
+ - [#5396](https://github.com/ardatan/graphql-tools/pull/5396)
95
+ [`bb8f169e`](https://github.com/ardatan/graphql-tools/commit/bb8f169e21a8a7002b66d3bc6e4e4b40cc2a5f5c)
96
+ Thanks [@ardatan](https://github.com/ardatan)! - Simplify GraphQL WS executor
97
+
98
+ - Updated dependencies
99
+ [[`bb8f169e`](https://github.com/ardatan/graphql-tools/commit/bb8f169e21a8a7002b66d3bc6e4e4b40cc2a5f5c),
100
+ [`bb8f169e`](https://github.com/ardatan/graphql-tools/commit/bb8f169e21a8a7002b66d3bc6e4e4b40cc2a5f5c)]:
101
+ - @graphql-tools/utils@10.0.2
102
+
103
+ ## 1.0.1
104
+
105
+ ### Patch Changes
106
+
107
+ - [#5374](https://github.com/ardatan/graphql-tools/pull/5374)
108
+ [`88a7de96`](https://github.com/ardatan/graphql-tools/commit/88a7de96c7766d94f9ac0adbe54523e585f8566c)
109
+ Thanks [@renovate](https://github.com/apps/renovate)! - dependencies updates:
110
+ - Updated dependency [`graphql-ws@5.14.0` ↗︎](https://www.npmjs.com/package/graphql-ws/v/5.14.0)
111
+ (from `5.13.1`, in `dependencies`)
112
+
113
+ ## 1.0.0
114
+
115
+ ### Major Changes
116
+
117
+ - [#5274](https://github.com/ardatan/graphql-tools/pull/5274)
118
+ [`944a68e8`](https://github.com/ardatan/graphql-tools/commit/944a68e8becf9c86b4c97fd17c372d98a285b955)
119
+ Thanks [@ardatan](https://github.com/ardatan)! - Drop Node 14 support. Require Node.js `>= 16`
120
+
121
+ ### Patch Changes
122
+
123
+ - [#5272](https://github.com/ardatan/graphql-tools/pull/5272)
124
+ [`3a870139`](https://github.com/ardatan/graphql-tools/commit/3a870139e13236f3ecc744666dd1c6fdb9f6be59)
125
+ Thanks [@renovate](https://github.com/apps/renovate)! - dependencies updates:
126
+
127
+ - Updated dependency [`graphql-ws@5.13.0` ↗︎](https://www.npmjs.com/package/graphql-ws/v/5.13.0)
128
+ (from `5.12.1`, in `dependencies`)
129
+
130
+ - [#5277](https://github.com/ardatan/graphql-tools/pull/5277)
131
+ [`853db708`](https://github.com/ardatan/graphql-tools/commit/853db70824fc86350a61bae415b7965fa2c06355)
132
+ Thanks [@renovate](https://github.com/apps/renovate)! - dependencies updates:
133
+ - Updated dependency [`graphql-ws@5.13.1` ↗︎](https://www.npmjs.com/package/graphql-ws/v/5.13.1)
134
+ (from `5.13.0`, in `dependencies`)
135
+ - Updated dependencies
136
+ [[`944a68e8`](https://github.com/ardatan/graphql-tools/commit/944a68e8becf9c86b4c97fd17c372d98a285b955),
137
+ [`944a68e8`](https://github.com/ardatan/graphql-tools/commit/944a68e8becf9c86b4c97fd17c372d98a285b955)]:
138
+ - @graphql-tools/utils@10.0.0
139
+
140
+ ## 0.0.14
141
+
142
+ ### Patch Changes
143
+
144
+ - [`1c95368a`](https://github.com/ardatan/graphql-tools/commit/1c95368aea868be537d956ba5e994cde58dfee41)
145
+ Thanks [@ardatan](https://github.com/ardatan)! - Use ranged versions for dependencies
146
+
147
+ ## 0.0.13
148
+
149
+ ### Patch Changes
150
+
151
+ - [#5112](https://github.com/ardatan/graphql-tools/pull/5112)
152
+ [`828fbf93`](https://github.com/ardatan/graphql-tools/commit/828fbf93ff317d00577c9a94402736bac5f4be39)
153
+ Thanks [@renovate](https://github.com/apps/renovate)! - dependencies updates:
154
+ - Updated dependency [`ws@8.13.0` ↗︎](https://www.npmjs.com/package/ws/v/8.13.0) (from `8.12.1`,
155
+ in `dependencies`)
156
+ - Updated dependency [`graphql-ws@5.12.1` ↗︎](https://www.npmjs.com/package/graphql-ws/v/5.12.1)
157
+ (from `5.12.0`, in `dependencies`)
158
+
159
+ ## 0.0.12
160
+
161
+ ### Patch Changes
162
+
163
+ - [#5096](https://github.com/ardatan/graphql-tools/pull/5096)
164
+ [`a5073e85`](https://github.com/ardatan/graphql-tools/commit/a5073e85124fa90db9dda606ed70a4a560d95737)
165
+ Thanks [@renovate](https://github.com/apps/renovate)! - dependencies updates:
166
+ - Updated dependency [`graphql-ws@5.12.0` ↗︎](https://www.npmjs.com/package/graphql-ws/v/5.12.0)
167
+ (from `5.11.3`, in `dependencies`)
168
+
169
+ ## 0.0.11
170
+
171
+ ### Patch Changes
172
+
173
+ - [#5058](https://github.com/ardatan/graphql-tools/pull/5058)
174
+ [`1298727c`](https://github.com/ardatan/graphql-tools/commit/1298727c629b4d535b023dcf920639ae43571692)
175
+ Thanks [@renovate](https://github.com/apps/renovate)! - dependencies updates:
176
+ - Updated dependency [`ws@8.12.1` ↗︎](https://www.npmjs.com/package/ws/v/8.12.1) (from `8.12.0`,
177
+ in `dependencies`)
178
+
179
+ ## 0.0.10
180
+
181
+ ### Patch Changes
182
+
183
+ - Updated dependencies
184
+ [[`b5c8f640`](https://github.com/ardatan/graphql-tools/commit/b5c8f6407b74466ed0d2989000458cb59239e9af)]:
185
+ - @graphql-tools/utils@9.2.1
186
+
187
+ ## 0.0.9
188
+
189
+ ### Patch Changes
190
+
191
+ - [#5020](https://github.com/ardatan/graphql-tools/pull/5020)
192
+ [`d104ce50`](https://github.com/ardatan/graphql-tools/commit/d104ce50a9ee18e92ffc92c39ff87e1cffc2aa19)
193
+ Thanks [@renovate](https://github.com/apps/renovate)! - dependencies updates:
194
+ - Updated dependency [`graphql-ws@5.11.3` ↗︎](https://www.npmjs.com/package/graphql-ws/v/5.11.3)
195
+ (from `5.11.2`, in `dependencies`)
196
+
197
+ ## 0.0.8
198
+
199
+ ### Patch Changes
200
+
201
+ - Updated dependencies
202
+ [[`a94217e9`](https://github.com/ardatan/graphql-tools/commit/a94217e920c5d6237471ab6ad4d96cf230984177),
203
+ [`62d074be`](https://github.com/ardatan/graphql-tools/commit/62d074be48779b1e096e056ca1233822c421dc99)]:
204
+ - @graphql-tools/utils@9.2.0
205
+
206
+ ## 0.0.7
207
+
208
+ ### Patch Changes
209
+
210
+ - [`1c291f33`](https://github.com/ardatan/graphql-tools/commit/1c291f33ba5e42126b5335530c1ac4cd6b3eaf6a)
211
+ Thanks [@ardatan](https://github.com/ardatan)! - Support regular queries and mutations in WS
212
+ Executor
213
+
214
+ ## 0.0.6
215
+
216
+ ### Patch Changes
217
+
218
+ - [#4952](https://github.com/ardatan/graphql-tools/pull/4952)
219
+ [`1c4853cb`](https://github.com/ardatan/graphql-tools/commit/1c4853cb8563d83c0d862d3c11257c48c7d1469c)
220
+ Thanks [@renovate](https://github.com/apps/renovate)! - dependencies updates:
221
+ - Updated dependency [`ws@8.12.0` ↗︎](https://www.npmjs.com/package/ws/v/8.12.0) (from `8.11.0`,
222
+ in `dependencies`)
223
+ - Updated dependencies
224
+ [[`e3ec35ed`](https://github.com/ardatan/graphql-tools/commit/e3ec35ed27d4a329739c8da6be06ce74c8f25591)]:
225
+ - @graphql-tools/utils@9.1.4
226
+
227
+ ## 0.0.5
228
+
229
+ ### Patch Changes
230
+
231
+ - Updated dependencies
232
+ [[`904fe770`](https://github.com/ardatan/graphql-tools/commit/904fe770a355ee3d79464c3bbf0375d2dcd64759)]:
233
+ - @graphql-tools/utils@9.1.3
234
+
235
+ ## 0.0.4
236
+
237
+ ### Patch Changes
238
+
239
+ - Updated dependencies
240
+ [[`13c24883`](https://github.com/ardatan/graphql-tools/commit/13c24883004d5330f7402cb20566e37535c5729b)]:
241
+ - @graphql-tools/utils@9.1.2
242
+
243
+ ## 0.0.3
244
+
245
+ ### Patch Changes
246
+
247
+ - Updated dependencies
248
+ [[`7411a5e7`](https://github.com/ardatan/graphql-tools/commit/7411a5e71a8138d9ccfe907b1fb01e62fcbb0cdb)]:
249
+ - @graphql-tools/utils@9.1.1
250
+
251
+ ## 0.0.2
252
+
253
+ ### Patch Changes
254
+
255
+ - [`e2fc041e`](https://github.com/ardatan/graphql-tools/commit/e2fc041e6f751c70efc20e8a02cbf88da0b905d2)
256
+ Thanks [@ardatan](https://github.com/ardatan)! - Improve typings
257
+
258
+ ## 0.0.1
259
+
260
+ ### Patch Changes
261
+
262
+ - [#4829](https://github.com/ardatan/graphql-tools/pull/4829)
263
+ [`61812ccb`](https://github.com/ardatan/graphql-tools/commit/61812ccb97d6e179e74d72661dd0736f6ca0a7ff)
264
+ Thanks [@ardatan](https://github.com/ardatan)! - Break down UrlLoader into different pieces
package/dist/index.cjs ADDED
@@ -0,0 +1,80 @@
1
+ 'use strict';
2
+
3
+ var utils = require('@graphql-tools/utils');
4
+ var disposablestack = require('@whatwg-node/disposablestack');
5
+ var graphql = require('graphql');
6
+ var graphqlWs = require('graphql-ws');
7
+ var WebSocket = require('isomorphic-ws');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
+
11
+ var WebSocket__default = /*#__PURE__*/_interopDefault(WebSocket);
12
+
13
+ const defaultPrintFn = utils.memoize1(graphql.print);
14
+ function isClient(client) {
15
+ return "subscribe" in client;
16
+ }
17
+ function buildGraphQLWSExecutor(clientOptionsOrClient) {
18
+ let graphqlWSClient;
19
+ let executorConnectionParams = {};
20
+ let printFn = defaultPrintFn;
21
+ if (isClient(clientOptionsOrClient)) {
22
+ graphqlWSClient = clientOptionsOrClient;
23
+ } else {
24
+ if (clientOptionsOrClient.print) {
25
+ printFn = clientOptionsOrClient.print;
26
+ }
27
+ const webSocketImpl = clientOptionsOrClient.headers ? class WebSocketWithHeaders extends WebSocket__default.default {
28
+ constructor(url, protocol) {
29
+ super(url, protocol, {
30
+ headers: clientOptionsOrClient.headers
31
+ });
32
+ }
33
+ } : WebSocket__default.default;
34
+ graphqlWSClient = graphqlWs.createClient({
35
+ webSocketImpl,
36
+ lazy: true,
37
+ ...clientOptionsOrClient,
38
+ connectionParams: () => {
39
+ const optionsConnectionParams = (typeof clientOptionsOrClient.connectionParams === "function" ? clientOptionsOrClient.connectionParams() : clientOptionsOrClient.connectionParams) || {};
40
+ return Object.assign(optionsConnectionParams, executorConnectionParams);
41
+ }
42
+ });
43
+ if (clientOptionsOrClient.onClient) {
44
+ clientOptionsOrClient.onClient(graphqlWSClient);
45
+ }
46
+ }
47
+ const executor = function GraphQLWSExecutor(executionRequest) {
48
+ const {
49
+ document,
50
+ variables,
51
+ operationName,
52
+ extensions,
53
+ operationType = utils.getOperationASTFromRequest(executionRequest).operation
54
+ } = executionRequest;
55
+ if (extensions?.["connectionParams"] && typeof extensions?.["connectionParams"] === "object") {
56
+ executorConnectionParams = Object.assign(
57
+ executorConnectionParams,
58
+ extensions["connectionParams"]
59
+ );
60
+ }
61
+ const query = printFn(document);
62
+ const iterableIterator = graphqlWSClient.iterate({
63
+ query,
64
+ variables,
65
+ operationName,
66
+ extensions
67
+ });
68
+ if (operationType === "subscription") {
69
+ return iterableIterator;
70
+ }
71
+ return iterableIterator.next().then(({ value }) => value);
72
+ };
73
+ const disposableExecutor = executor;
74
+ disposableExecutor[disposablestack.DisposableSymbols.asyncDispose] = function disposeWS() {
75
+ return graphqlWSClient.dispose();
76
+ };
77
+ return disposableExecutor;
78
+ }
79
+
80
+ exports.buildGraphQLWSExecutor = buildGraphQLWSExecutor;
@@ -1,6 +1,7 @@
1
+ import { DisposableExecutor } from '@graphql-tools/utils';
1
2
  import { print } from 'graphql';
2
3
  import { Client, ClientOptions } from 'graphql-ws';
3
- import { DisposableExecutor } from '@graphql-tools/utils';
4
+
4
5
  interface GraphQLWSExecutorOptions extends ClientOptions {
5
6
  onClient?: (client: Client) => void;
6
7
  print?: typeof print;
@@ -12,5 +13,6 @@ interface GraphQLWSExecutorOptions extends ClientOptions {
12
13
  */
13
14
  headers?: Record<string, string>;
14
15
  }
15
- export declare function buildGraphQLWSExecutor(clientOptionsOrClient: GraphQLWSExecutorOptions | Client): DisposableExecutor;
16
- export {};
16
+ declare function buildGraphQLWSExecutor(clientOptionsOrClient: GraphQLWSExecutorOptions | Client): DisposableExecutor;
17
+
18
+ export { buildGraphQLWSExecutor };
@@ -1,6 +1,7 @@
1
+ import { DisposableExecutor } from '@graphql-tools/utils';
1
2
  import { print } from 'graphql';
2
3
  import { Client, ClientOptions } from 'graphql-ws';
3
- import { DisposableExecutor } from '@graphql-tools/utils';
4
+
4
5
  interface GraphQLWSExecutorOptions extends ClientOptions {
5
6
  onClient?: (client: Client) => void;
6
7
  print?: typeof print;
@@ -12,5 +13,6 @@ interface GraphQLWSExecutorOptions extends ClientOptions {
12
13
  */
13
14
  headers?: Record<string, string>;
14
15
  }
15
- export declare function buildGraphQLWSExecutor(clientOptionsOrClient: GraphQLWSExecutorOptions | Client): DisposableExecutor;
16
- export {};
16
+ declare function buildGraphQLWSExecutor(clientOptionsOrClient: GraphQLWSExecutorOptions | Client): DisposableExecutor;
17
+
18
+ export { buildGraphQLWSExecutor };
package/dist/index.js ADDED
@@ -0,0 +1,74 @@
1
+ import { memoize1, getOperationASTFromRequest } from '@graphql-tools/utils';
2
+ import { DisposableSymbols } from '@whatwg-node/disposablestack';
3
+ import { print } from 'graphql';
4
+ import { createClient } from 'graphql-ws';
5
+ import WebSocket from 'isomorphic-ws';
6
+
7
+ const defaultPrintFn = memoize1(print);
8
+ function isClient(client) {
9
+ return "subscribe" in client;
10
+ }
11
+ function buildGraphQLWSExecutor(clientOptionsOrClient) {
12
+ let graphqlWSClient;
13
+ let executorConnectionParams = {};
14
+ let printFn = defaultPrintFn;
15
+ if (isClient(clientOptionsOrClient)) {
16
+ graphqlWSClient = clientOptionsOrClient;
17
+ } else {
18
+ if (clientOptionsOrClient.print) {
19
+ printFn = clientOptionsOrClient.print;
20
+ }
21
+ const webSocketImpl = clientOptionsOrClient.headers ? class WebSocketWithHeaders extends WebSocket {
22
+ constructor(url, protocol) {
23
+ super(url, protocol, {
24
+ headers: clientOptionsOrClient.headers
25
+ });
26
+ }
27
+ } : WebSocket;
28
+ graphqlWSClient = createClient({
29
+ webSocketImpl,
30
+ lazy: true,
31
+ ...clientOptionsOrClient,
32
+ connectionParams: () => {
33
+ const optionsConnectionParams = (typeof clientOptionsOrClient.connectionParams === "function" ? clientOptionsOrClient.connectionParams() : clientOptionsOrClient.connectionParams) || {};
34
+ return Object.assign(optionsConnectionParams, executorConnectionParams);
35
+ }
36
+ });
37
+ if (clientOptionsOrClient.onClient) {
38
+ clientOptionsOrClient.onClient(graphqlWSClient);
39
+ }
40
+ }
41
+ const executor = function GraphQLWSExecutor(executionRequest) {
42
+ const {
43
+ document,
44
+ variables,
45
+ operationName,
46
+ extensions,
47
+ operationType = getOperationASTFromRequest(executionRequest).operation
48
+ } = executionRequest;
49
+ if (extensions?.["connectionParams"] && typeof extensions?.["connectionParams"] === "object") {
50
+ executorConnectionParams = Object.assign(
51
+ executorConnectionParams,
52
+ extensions["connectionParams"]
53
+ );
54
+ }
55
+ const query = printFn(document);
56
+ const iterableIterator = graphqlWSClient.iterate({
57
+ query,
58
+ variables,
59
+ operationName,
60
+ extensions
61
+ });
62
+ if (operationType === "subscription") {
63
+ return iterableIterator;
64
+ }
65
+ return iterableIterator.next().then(({ value }) => value);
66
+ };
67
+ const disposableExecutor = executor;
68
+ disposableExecutor[DisposableSymbols.asyncDispose] = function disposeWS() {
69
+ return graphqlWSClient.dispose();
70
+ };
71
+ return disposableExecutor;
72
+ }
73
+
74
+ export { buildGraphQLWSExecutor };
package/package.json CHANGED
@@ -1,65 +1,55 @@
1
1
  {
2
2
  "name": "@graphql-tools/executor-graphql-ws",
3
- "version": "1.3.2",
3
+ "version": "1.3.3-alpha-63d80f9d08b5d8448f4bfb8b04aeff28b977dec8",
4
+ "type": "module",
4
5
  "description": "A set of utils for faster development of GraphQL tools",
5
- "sideEffects": false,
6
- "peerDependencies": {
7
- "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
8
- },
9
- "dependencies": {
10
- "@graphql-tools/utils": "^10.5.6",
11
- "@types/ws": "^8.0.0",
12
- "graphql-ws": "^5.14.0",
13
- "isomorphic-ws": "^5.0.0",
14
- "tslib": "^2.4.0",
15
- "ws": "^8.17.1"
16
- },
17
6
  "repository": {
18
7
  "type": "git",
19
- "url": "ardatan/graphql-tools",
8
+ "url": "graphql-hive/gateway",
20
9
  "directory": "packages/executors/graphql-ws"
21
10
  },
22
11
  "author": "Arda TANRIKULU <ardatanrikulu@gmail.com>",
23
12
  "license": "MIT",
24
13
  "engines": {
25
- "node": ">=16.0.0"
14
+ "node": ">=18.0.0"
26
15
  },
27
- "main": "cjs/index.js",
28
- "module": "esm/index.js",
29
- "typings": "typings/index.d.ts",
30
- "typescript": {
31
- "definition": "typings/index.d.ts"
32
- },
33
- "type": "module",
16
+ "main": "./dist/index.js",
34
17
  "exports": {
35
18
  ".": {
36
19
  "require": {
37
- "types": "./typings/index.d.cts",
38
- "default": "./cjs/index.js"
20
+ "types": "./dist/index.d.cts",
21
+ "default": "./dist/index.cjs"
39
22
  },
40
23
  "import": {
41
- "types": "./typings/index.d.ts",
42
- "default": "./esm/index.js"
43
- },
44
- "default": {
45
- "types": "./typings/index.d.ts",
46
- "default": "./esm/index.js"
47
- }
48
- },
49
- "./*": {
50
- "require": {
51
- "types": "./typings/*.d.cts",
52
- "default": "./cjs/*.js"
53
- },
54
- "import": {
55
- "types": "./typings/*.d.ts",
56
- "default": "./esm/*.js"
57
- },
58
- "default": {
59
- "types": "./typings/*.d.ts",
60
- "default": "./esm/*.js"
24
+ "types": "./dist/index.d.ts",
25
+ "default": "./dist/index.js"
61
26
  }
62
27
  },
63
28
  "./package.json": "./package.json"
64
- }
29
+ },
30
+ "types": "./dist/index.d.ts",
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "scripts": {
35
+ "build": "pkgroll --clean-dist",
36
+ "prepack": "yarn build"
37
+ },
38
+ "peerDependencies": {
39
+ "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
40
+ },
41
+ "dependencies": {
42
+ "@graphql-tools/utils": "^10.6.0",
43
+ "@whatwg-node/disposablestack": "^0.0.5",
44
+ "graphql-ws": "^5.14.0",
45
+ "isomorphic-ws": "^5.0.0",
46
+ "tslib": "^2.4.0",
47
+ "ws": "^8.17.1"
48
+ },
49
+ "devDependencies": {
50
+ "@types/ws": "^8.0.0",
51
+ "graphql": "^16.9.0",
52
+ "pkgroll": "2.5.1"
53
+ },
54
+ "sideEffects": false
65
55
  }
package/cjs/index.js DELETED
@@ -1,73 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildGraphQLWSExecutor = void 0;
4
- const tslib_1 = require("tslib");
5
- const graphql_1 = require("graphql");
6
- const graphql_ws_1 = require("graphql-ws");
7
- const isomorphic_ws_1 = tslib_1.__importDefault(require("isomorphic-ws"));
8
- const utils_1 = require("@graphql-tools/utils");
9
- const defaultPrintFn = (0, utils_1.memoize1)(graphql_1.print);
10
- function isClient(client) {
11
- return 'subscribe' in client;
12
- }
13
- function buildGraphQLWSExecutor(clientOptionsOrClient) {
14
- let graphqlWSClient;
15
- let executorConnectionParams = {};
16
- let printFn = defaultPrintFn;
17
- if (isClient(clientOptionsOrClient)) {
18
- graphqlWSClient = clientOptionsOrClient;
19
- }
20
- else {
21
- if (clientOptionsOrClient.print) {
22
- printFn = clientOptionsOrClient.print;
23
- }
24
- const webSocketImpl = clientOptionsOrClient.headers
25
- ? class WebSocketWithHeaders extends isomorphic_ws_1.default {
26
- constructor(url, protocol) {
27
- super(url, protocol, {
28
- headers: clientOptionsOrClient.headers,
29
- });
30
- }
31
- }
32
- : isomorphic_ws_1.default;
33
- graphqlWSClient = (0, graphql_ws_1.createClient)({
34
- webSocketImpl,
35
- lazy: true,
36
- ...clientOptionsOrClient,
37
- connectionParams: () => {
38
- const optionsConnectionParams = (typeof clientOptionsOrClient.connectionParams === 'function'
39
- ? clientOptionsOrClient.connectionParams()
40
- : clientOptionsOrClient.connectionParams) || {};
41
- return Object.assign(optionsConnectionParams, executorConnectionParams);
42
- },
43
- });
44
- if (clientOptionsOrClient.onClient) {
45
- clientOptionsOrClient.onClient(graphqlWSClient);
46
- }
47
- }
48
- const executor = function GraphQLWSExecutor(executionRequest) {
49
- const { document, variables, operationName, extensions, operationType = (0, utils_1.getOperationASTFromRequest)(executionRequest).operation, } = executionRequest;
50
- // additional connection params can be supplied through the "connectionParams" field in extensions.
51
- // TODO: connection params only from the FIRST operation in lazy mode will be used (detect connectionParams changes and reconnect, too implicit?)
52
- if (extensions?.['connectionParams'] && typeof extensions?.['connectionParams'] === 'object') {
53
- executorConnectionParams = Object.assign(executorConnectionParams, extensions['connectionParams']);
54
- }
55
- const query = printFn(document);
56
- const iterableIterator = graphqlWSClient.iterate({
57
- query,
58
- variables,
59
- operationName,
60
- extensions,
61
- });
62
- if (operationType === 'subscription') {
63
- return iterableIterator;
64
- }
65
- return iterableIterator.next().then(({ value }) => value);
66
- };
67
- const disposableExecutor = executor;
68
- disposableExecutor[Symbol.asyncDispose] = function disposeWS() {
69
- return graphqlWSClient.dispose();
70
- };
71
- return disposableExecutor;
72
- }
73
- exports.buildGraphQLWSExecutor = buildGraphQLWSExecutor;
package/cjs/package.json DELETED
@@ -1 +0,0 @@
1
- {"type":"commonjs"}
package/esm/index.js DELETED
@@ -1,68 +0,0 @@
1
- import { print } from 'graphql';
2
- import { createClient } from 'graphql-ws';
3
- import WebSocket from 'isomorphic-ws';
4
- import { getOperationASTFromRequest, memoize1, } from '@graphql-tools/utils';
5
- const defaultPrintFn = memoize1(print);
6
- function isClient(client) {
7
- return 'subscribe' in client;
8
- }
9
- export function buildGraphQLWSExecutor(clientOptionsOrClient) {
10
- let graphqlWSClient;
11
- let executorConnectionParams = {};
12
- let printFn = defaultPrintFn;
13
- if (isClient(clientOptionsOrClient)) {
14
- graphqlWSClient = clientOptionsOrClient;
15
- }
16
- else {
17
- if (clientOptionsOrClient.print) {
18
- printFn = clientOptionsOrClient.print;
19
- }
20
- const webSocketImpl = clientOptionsOrClient.headers
21
- ? class WebSocketWithHeaders extends WebSocket {
22
- constructor(url, protocol) {
23
- super(url, protocol, {
24
- headers: clientOptionsOrClient.headers,
25
- });
26
- }
27
- }
28
- : WebSocket;
29
- graphqlWSClient = createClient({
30
- webSocketImpl,
31
- lazy: true,
32
- ...clientOptionsOrClient,
33
- connectionParams: () => {
34
- const optionsConnectionParams = (typeof clientOptionsOrClient.connectionParams === 'function'
35
- ? clientOptionsOrClient.connectionParams()
36
- : clientOptionsOrClient.connectionParams) || {};
37
- return Object.assign(optionsConnectionParams, executorConnectionParams);
38
- },
39
- });
40
- if (clientOptionsOrClient.onClient) {
41
- clientOptionsOrClient.onClient(graphqlWSClient);
42
- }
43
- }
44
- const executor = function GraphQLWSExecutor(executionRequest) {
45
- const { document, variables, operationName, extensions, operationType = getOperationASTFromRequest(executionRequest).operation, } = executionRequest;
46
- // additional connection params can be supplied through the "connectionParams" field in extensions.
47
- // TODO: connection params only from the FIRST operation in lazy mode will be used (detect connectionParams changes and reconnect, too implicit?)
48
- if (extensions?.['connectionParams'] && typeof extensions?.['connectionParams'] === 'object') {
49
- executorConnectionParams = Object.assign(executorConnectionParams, extensions['connectionParams']);
50
- }
51
- const query = printFn(document);
52
- const iterableIterator = graphqlWSClient.iterate({
53
- query,
54
- variables,
55
- operationName,
56
- extensions,
57
- });
58
- if (operationType === 'subscription') {
59
- return iterableIterator;
60
- }
61
- return iterableIterator.next().then(({ value }) => value);
62
- };
63
- const disposableExecutor = executor;
64
- disposableExecutor[Symbol.asyncDispose] = function disposeWS() {
65
- return graphqlWSClient.dispose();
66
- };
67
- return disposableExecutor;
68
- }