@graphql-tools/url-loader 7.9.11 → 7.9.12-alpha-4f055a1d.0

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/index.d.ts CHANGED
@@ -5,7 +5,6 @@ import { AsyncExecutor, Executor, SyncExecutor, Source, Loader, BaseLoaderOption
5
5
  import { ClientOptions } from 'graphql-ws';
6
6
  import { ClientOptions as GraphQLSSEClientOptions } from 'graphql-sse';
7
7
  import WebSocket from 'isomorphic-ws';
8
- import { ConnectionParamsOptions } from 'subscriptions-transport-ws';
9
8
  import { AsyncFetchFn } from './defaultAsyncFetch';
10
9
  import { SyncFetchFn } from './defaultSyncFetch';
11
10
  export declare type FetchFn = AsyncFetchFn | SyncFetchFn;
@@ -123,7 +122,7 @@ export declare class UrlLoader implements Loader<LoadFromUrlOptions> {
123
122
  buildHTTPExecutor(endpoint: string, fetch: SyncFetchFn, options?: LoadFromUrlOptions): SyncExecutor<any, ExecutionExtensions>;
124
123
  buildHTTPExecutor(endpoint: string, fetch: AsyncFetchFn, options?: LoadFromUrlOptions): AsyncExecutor<any, ExecutionExtensions>;
125
124
  buildWSExecutor(subscriptionsEndpoint: string, webSocketImpl: typeof WebSocket, connectionParams?: ClientOptions['connectionParams']): Executor;
126
- buildWSLegacyExecutor(subscriptionsEndpoint: string, webSocketImpl: typeof WebSocket, connectionParams?: ConnectionParamsOptions): Executor;
125
+ buildWSLegacyExecutor(subscriptionsEndpoint: string, WebSocketImpl: typeof WebSocket, options?: LoadFromUrlOptions): Executor;
127
126
  buildGraphQLSSEExecutor(endpoint: string, fetch: AsyncFetchFn, options?: Omit<LoadFromUrlOptions, 'subscriptionEndpoint'>): AsyncExecutor;
128
127
  getFetch(customFetch: LoadFromUrlOptions['customFetch'], importFn: AsyncImportFn): PromiseLike<AsyncFetchFn> | AsyncFetchFn;
129
128
  getFetch(customFetch: LoadFromUrlOptions['customFetch'], importFn: SyncImportFn): SyncFetchFn;
package/index.js CHANGED
@@ -30,7 +30,6 @@ const graphqlWs = require('graphql-ws');
30
30
  const graphqlSse = require('graphql-sse');
31
31
  const WebSocket = _interopDefault(require('isomorphic-ws'));
32
32
  const extractFiles = require('extract-files');
33
- const subscriptionsTransportWs = require('subscriptions-transport-ws');
34
33
  const valueOrPromise = require('value-or-promise');
35
34
  const graphqlLiveQuery = require('@n1ru4l/graphql-live-query');
36
35
  const crossUndiciFetch = require('cross-undici-fetch');
@@ -276,6 +275,19 @@ function isGraphQLUpload(upload) {
276
275
  function isPromiseLike(obj) {
277
276
  return typeof obj.then === 'function';
278
277
  }
278
+ var LEGACY_WS;
279
+ (function (LEGACY_WS) {
280
+ LEGACY_WS["CONNECTION_INIT"] = "connection_init";
281
+ LEGACY_WS["CONNECTION_ACK"] = "connection_ack";
282
+ LEGACY_WS["CONNECTION_ERROR"] = "connection_error";
283
+ LEGACY_WS["CONNECTION_KEEP_ALIVE"] = "ka";
284
+ LEGACY_WS["START"] = "start";
285
+ LEGACY_WS["STOP"] = "stop";
286
+ LEGACY_WS["CONNECTION_TERMINATE"] = "connection_terminate";
287
+ LEGACY_WS["DATA"] = "data";
288
+ LEGACY_WS["ERROR"] = "error";
289
+ LEGACY_WS["COMPLETE"] = "complete";
290
+ })(LEGACY_WS || (LEGACY_WS = {}));
279
291
 
280
292
  /* eslint-disable no-case-declarations */
281
293
  const asyncImport = (moduleName) => new Promise(function (resolve) { resolve(_interopNamespace(require(moduleName))); });
@@ -581,21 +593,79 @@ class UrlLoader {
581
593
  });
582
594
  };
583
595
  }
584
- buildWSLegacyExecutor(subscriptionsEndpoint, webSocketImpl, connectionParams) {
596
+ buildWSLegacyExecutor(subscriptionsEndpoint, WebSocketImpl, options) {
585
597
  const WS_URL = switchProtocols(subscriptionsEndpoint, {
586
598
  https: 'wss',
587
599
  http: 'ws',
588
600
  });
589
- const subscriptionClient = new subscriptionsTransportWs.SubscriptionClient(WS_URL, {
590
- connectionParams,
591
- lazy: true,
592
- }, webSocketImpl);
593
- return ({ document, variables, operationName, }) => {
594
- return utils.observableToAsyncIterable(subscriptionClient.request({
595
- query: document,
596
- variables,
597
- operationName,
598
- }));
601
+ return function legacyExecutor(request) {
602
+ const id = Date.now().toString();
603
+ return utils.observableToAsyncIterable({
604
+ subscribe(observer) {
605
+ const websocket = new WebSocketImpl(WS_URL, 'graphql-ws', {
606
+ followRedirects: true,
607
+ headers: options === null || options === void 0 ? void 0 : options.headers,
608
+ rejectUnauthorized: false,
609
+ skipUTF8Validation: true,
610
+ });
611
+ websocket.onopen = () => {
612
+ websocket.send(JSON.stringify({
613
+ type: LEGACY_WS.CONNECTION_INIT,
614
+ payload: {
615
+ ...request.extensions,
616
+ },
617
+ }));
618
+ };
619
+ websocket.onmessage = event => {
620
+ const data = JSON.parse(event.data.toString('utf-8'));
621
+ switch (data.type) {
622
+ case LEGACY_WS.CONNECTION_ACK: {
623
+ websocket.send(JSON.stringify({
624
+ type: LEGACY_WS.START,
625
+ id,
626
+ payload: {
627
+ query: graphql.print(request.document),
628
+ variables: request.variables,
629
+ operationName: request.operationName,
630
+ },
631
+ }));
632
+ break;
633
+ }
634
+ case LEGACY_WS.CONNECTION_ERROR: {
635
+ observer.error(data.payload);
636
+ break;
637
+ }
638
+ case LEGACY_WS.CONNECTION_KEEP_ALIVE: {
639
+ break;
640
+ }
641
+ case LEGACY_WS.DATA: {
642
+ observer.next(data.payload);
643
+ break;
644
+ }
645
+ case LEGACY_WS.COMPLETE: {
646
+ websocket.send(JSON.stringify({
647
+ type: LEGACY_WS.CONNECTION_TERMINATE,
648
+ }));
649
+ websocket.terminate();
650
+ observer.complete();
651
+ break;
652
+ }
653
+ }
654
+ };
655
+ return {
656
+ unsubscribe: () => {
657
+ websocket.send(JSON.stringify({
658
+ type: LEGACY_WS.STOP,
659
+ id,
660
+ }));
661
+ websocket.send(JSON.stringify({
662
+ type: LEGACY_WS.CONNECTION_TERMINATE,
663
+ }));
664
+ websocket.terminate();
665
+ },
666
+ };
667
+ },
668
+ });
599
669
  };
600
670
  }
601
671
  buildGraphQLSSEExecutor(endpoint, fetch, options = {}) {
@@ -680,7 +750,7 @@ class UrlLoader {
680
750
  const connectionParams = () => ({ headers: options === null || options === void 0 ? void 0 : options.headers });
681
751
  const executor$ = webSocketImpl$.then(webSocketImpl => {
682
752
  if ((options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === exports.SubscriptionProtocol.LEGACY_WS) {
683
- return this.buildWSLegacyExecutor(subscriptionsEndpoint, webSocketImpl, connectionParams);
753
+ return this.buildWSLegacyExecutor(subscriptionsEndpoint, webSocketImpl, options);
684
754
  }
685
755
  else {
686
756
  return this.buildWSExecutor(subscriptionsEndpoint, webSocketImpl, connectionParams);
package/index.mjs CHANGED
@@ -5,7 +5,6 @@ import { createClient } from 'graphql-ws';
5
5
  import { createClient as createClient$1 } from 'graphql-sse';
6
6
  import WebSocket from 'isomorphic-ws';
7
7
  import { extractFiles, isExtractableFile } from 'extract-files';
8
- import { SubscriptionClient } from 'subscriptions-transport-ws';
9
8
  import { ValueOrPromise } from 'value-or-promise';
10
9
  import { isLiveQueryOperationDefinitionNode } from '@n1ru4l/graphql-live-query';
11
10
  import { fetch, FormData, AbortController, File } from 'cross-undici-fetch';
@@ -251,6 +250,19 @@ function isGraphQLUpload(upload) {
251
250
  function isPromiseLike(obj) {
252
251
  return typeof obj.then === 'function';
253
252
  }
253
+ var LEGACY_WS;
254
+ (function (LEGACY_WS) {
255
+ LEGACY_WS["CONNECTION_INIT"] = "connection_init";
256
+ LEGACY_WS["CONNECTION_ACK"] = "connection_ack";
257
+ LEGACY_WS["CONNECTION_ERROR"] = "connection_error";
258
+ LEGACY_WS["CONNECTION_KEEP_ALIVE"] = "ka";
259
+ LEGACY_WS["START"] = "start";
260
+ LEGACY_WS["STOP"] = "stop";
261
+ LEGACY_WS["CONNECTION_TERMINATE"] = "connection_terminate";
262
+ LEGACY_WS["DATA"] = "data";
263
+ LEGACY_WS["ERROR"] = "error";
264
+ LEGACY_WS["COMPLETE"] = "complete";
265
+ })(LEGACY_WS || (LEGACY_WS = {}));
254
266
 
255
267
  /* eslint-disable no-case-declarations */
256
268
  const asyncImport = (moduleName) => import(moduleName);
@@ -557,21 +569,79 @@ class UrlLoader {
557
569
  });
558
570
  };
559
571
  }
560
- buildWSLegacyExecutor(subscriptionsEndpoint, webSocketImpl, connectionParams) {
572
+ buildWSLegacyExecutor(subscriptionsEndpoint, WebSocketImpl, options) {
561
573
  const WS_URL = switchProtocols(subscriptionsEndpoint, {
562
574
  https: 'wss',
563
575
  http: 'ws',
564
576
  });
565
- const subscriptionClient = new SubscriptionClient(WS_URL, {
566
- connectionParams,
567
- lazy: true,
568
- }, webSocketImpl);
569
- return ({ document, variables, operationName, }) => {
570
- return observableToAsyncIterable(subscriptionClient.request({
571
- query: document,
572
- variables,
573
- operationName,
574
- }));
577
+ return function legacyExecutor(request) {
578
+ const id = Date.now().toString();
579
+ return observableToAsyncIterable({
580
+ subscribe(observer) {
581
+ const websocket = new WebSocketImpl(WS_URL, 'graphql-ws', {
582
+ followRedirects: true,
583
+ headers: options === null || options === void 0 ? void 0 : options.headers,
584
+ rejectUnauthorized: false,
585
+ skipUTF8Validation: true,
586
+ });
587
+ websocket.onopen = () => {
588
+ websocket.send(JSON.stringify({
589
+ type: LEGACY_WS.CONNECTION_INIT,
590
+ payload: {
591
+ ...request.extensions,
592
+ },
593
+ }));
594
+ };
595
+ websocket.onmessage = event => {
596
+ const data = JSON.parse(event.data.toString('utf-8'));
597
+ switch (data.type) {
598
+ case LEGACY_WS.CONNECTION_ACK: {
599
+ websocket.send(JSON.stringify({
600
+ type: LEGACY_WS.START,
601
+ id,
602
+ payload: {
603
+ query: print(request.document),
604
+ variables: request.variables,
605
+ operationName: request.operationName,
606
+ },
607
+ }));
608
+ break;
609
+ }
610
+ case LEGACY_WS.CONNECTION_ERROR: {
611
+ observer.error(data.payload);
612
+ break;
613
+ }
614
+ case LEGACY_WS.CONNECTION_KEEP_ALIVE: {
615
+ break;
616
+ }
617
+ case LEGACY_WS.DATA: {
618
+ observer.next(data.payload);
619
+ break;
620
+ }
621
+ case LEGACY_WS.COMPLETE: {
622
+ websocket.send(JSON.stringify({
623
+ type: LEGACY_WS.CONNECTION_TERMINATE,
624
+ }));
625
+ websocket.terminate();
626
+ observer.complete();
627
+ break;
628
+ }
629
+ }
630
+ };
631
+ return {
632
+ unsubscribe: () => {
633
+ websocket.send(JSON.stringify({
634
+ type: LEGACY_WS.STOP,
635
+ id,
636
+ }));
637
+ websocket.send(JSON.stringify({
638
+ type: LEGACY_WS.CONNECTION_TERMINATE,
639
+ }));
640
+ websocket.terminate();
641
+ },
642
+ };
643
+ },
644
+ });
575
645
  };
576
646
  }
577
647
  buildGraphQLSSEExecutor(endpoint, fetch, options = {}) {
@@ -656,7 +726,7 @@ class UrlLoader {
656
726
  const connectionParams = () => ({ headers: options === null || options === void 0 ? void 0 : options.headers });
657
727
  const executor$ = webSocketImpl$.then(webSocketImpl => {
658
728
  if ((options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === SubscriptionProtocol.LEGACY_WS) {
659
- return this.buildWSLegacyExecutor(subscriptionsEndpoint, webSocketImpl, connectionParams);
729
+ return this.buildWSLegacyExecutor(subscriptionsEndpoint, webSocketImpl, options);
660
730
  }
661
731
  else {
662
732
  return this.buildWSExecutor(subscriptionsEndpoint, webSocketImpl, connectionParams);
package/package.json CHANGED
@@ -1,15 +1,17 @@
1
1
  {
2
2
  "name": "@graphql-tools/url-loader",
3
- "version": "7.9.11",
3
+ "version": "7.9.12-alpha-4f055a1d.0",
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"
8
8
  },
9
9
  "dependencies": {
10
+ "@envelop/live-query": "3.3.0",
10
11
  "@graphql-tools/delegate": "8.7.4",
11
12
  "@graphql-tools/utils": "8.6.7",
12
13
  "@graphql-tools/wrap": "8.4.13",
14
+ "@graphql-yoga/node": "2.2.1",
13
15
  "@n1ru4l/graphql-live-query": "^0.9.0",
14
16
  "@types/websocket": "^1.0.4",
15
17
  "@types/ws": "^8.0.0",
@@ -20,7 +22,6 @@
20
22
  "graphql-ws": "^5.4.1",
21
23
  "isomorphic-ws": "^4.0.1",
22
24
  "meros": "^1.1.4",
23
- "subscriptions-transport-ws": "^0.11.0",
24
25
  "sync-fetch": "^0.3.1",
25
26
  "tslib": "^2.3.0",
26
27
  "value-or-promise": "^1.0.11",
package/utils.d.ts CHANGED
@@ -8,4 +8,16 @@ interface GraphQLUpload {
8
8
  }
9
9
  export declare function isGraphQLUpload(upload: any): upload is GraphQLUpload;
10
10
  export declare function isPromiseLike(obj: any): obj is PromiseLike<any>;
11
+ export declare enum LEGACY_WS {
12
+ CONNECTION_INIT = "connection_init",
13
+ CONNECTION_ACK = "connection_ack",
14
+ CONNECTION_ERROR = "connection_error",
15
+ CONNECTION_KEEP_ALIVE = "ka",
16
+ START = "start",
17
+ STOP = "stop",
18
+ CONNECTION_TERMINATE = "connection_terminate",
19
+ DATA = "data",
20
+ ERROR = "error",
21
+ COMPLETE = "complete"
22
+ }
11
23
  export {};