@graphql-tools/url-loader 7.9.12-alpha-7f601ea5.0 → 7.9.13
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 +3 -6
- package/index.js +101 -56
- package/index.mjs +102 -57
- package/package.json +5 -9
- package/utils.d.ts +12 -0
package/index.d.ts
CHANGED
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
import { IntrospectionOptions } from 'graphql';
|
|
4
4
|
import { AsyncExecutor, Executor, SyncExecutor, Source, Loader, BaseLoaderOptions } from '@graphql-tools/utils';
|
|
5
5
|
import { ClientOptions } from 'graphql-ws';
|
|
6
|
-
import { ClientOptions as GraphQLSSEClientOptions } from 'graphql-sse';
|
|
7
6
|
import WebSocket from 'isomorphic-ws';
|
|
8
|
-
import { ConnectionParamsOptions } from 'subscriptions-transport-ws';
|
|
9
7
|
import { AsyncFetchFn } from './defaultAsyncFetch';
|
|
10
8
|
import { SyncFetchFn } from './defaultSyncFetch';
|
|
11
9
|
export declare type FetchFn = AsyncFetchFn | SyncFetchFn;
|
|
@@ -78,9 +76,9 @@ export interface LoadFromUrlOptions extends BaseLoaderOptions, Partial<Introspec
|
|
|
78
76
|
*/
|
|
79
77
|
subscriptionsProtocol?: SubscriptionProtocol;
|
|
80
78
|
/**
|
|
81
|
-
*
|
|
79
|
+
* @deprecated This is no longer used. Will be removed in the next release
|
|
82
80
|
*/
|
|
83
|
-
graphqlSseOptions?:
|
|
81
|
+
graphqlSseOptions?: any;
|
|
84
82
|
/**
|
|
85
83
|
* Retry attempts
|
|
86
84
|
*/
|
|
@@ -123,8 +121,7 @@ export declare class UrlLoader implements Loader<LoadFromUrlOptions> {
|
|
|
123
121
|
buildHTTPExecutor(endpoint: string, fetch: SyncFetchFn, options?: LoadFromUrlOptions): SyncExecutor<any, ExecutionExtensions>;
|
|
124
122
|
buildHTTPExecutor(endpoint: string, fetch: AsyncFetchFn, options?: LoadFromUrlOptions): AsyncExecutor<any, ExecutionExtensions>;
|
|
125
123
|
buildWSExecutor(subscriptionsEndpoint: string, webSocketImpl: typeof WebSocket, connectionParams?: ClientOptions['connectionParams']): Executor;
|
|
126
|
-
buildWSLegacyExecutor(subscriptionsEndpoint: string,
|
|
127
|
-
buildGraphQLSSEExecutor(endpoint: string, fetch: AsyncFetchFn, options?: Omit<LoadFromUrlOptions, 'subscriptionEndpoint'>): AsyncExecutor;
|
|
124
|
+
buildWSLegacyExecutor(subscriptionsEndpoint: string, WebSocketImpl: typeof WebSocket, options?: LoadFromUrlOptions): Executor;
|
|
128
125
|
getFetch(customFetch: LoadFromUrlOptions['customFetch'], importFn: AsyncImportFn): PromiseLike<AsyncFetchFn> | AsyncFetchFn;
|
|
129
126
|
getFetch(customFetch: LoadFromUrlOptions['customFetch'], importFn: SyncImportFn): SyncFetchFn;
|
|
130
127
|
private getDefaultMethodFromOptions;
|
package/index.js
CHANGED
|
@@ -27,10 +27,8 @@ const graphql = require('graphql');
|
|
|
27
27
|
const utils = require('@graphql-tools/utils');
|
|
28
28
|
const wrap = require('@graphql-tools/wrap');
|
|
29
29
|
const graphqlWs = require('graphql-ws');
|
|
30
|
-
const graphqlSse = require('graphql-sse');
|
|
31
30
|
const WebSocket = _interopDefault(require('isomorphic-ws'));
|
|
32
31
|
const extractFiles = require('extract-files');
|
|
33
|
-
const subscriptionsTransportWs = require('subscriptions-transport-ws');
|
|
34
32
|
const valueOrPromise = require('value-or-promise');
|
|
35
33
|
const graphqlLiveQuery = require('@n1ru4l/graphql-live-query');
|
|
36
34
|
const crossUndiciFetch = require('cross-undici-fetch');
|
|
@@ -99,10 +97,17 @@ async function handleMultipartMixedResponse(response) {
|
|
|
99
97
|
}
|
|
100
98
|
|
|
101
99
|
/* eslint-disable no-labels */
|
|
100
|
+
let decodeUint8Array;
|
|
101
|
+
if (globalThis.Buffer) {
|
|
102
|
+
decodeUint8Array = uint8Array => globalThis.Buffer.from(uint8Array).toString('utf-8');
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
const textDecoder = new TextDecoder();
|
|
106
|
+
decodeUint8Array = uint8Array => textDecoder.decode(uint8Array);
|
|
107
|
+
}
|
|
102
108
|
async function* handleReadable(readable) {
|
|
103
|
-
const decoder = new TextDecoder();
|
|
104
109
|
outer: for await (const chunk of readable) {
|
|
105
|
-
const chunkStr = typeof chunk === 'string' ? chunk :
|
|
110
|
+
const chunkStr = typeof chunk === 'string' ? chunk : decodeUint8Array(chunk);
|
|
106
111
|
for (const part of chunkStr.split('\n\n')) {
|
|
107
112
|
if (part) {
|
|
108
113
|
const eventStr = part.split('event: ')[1];
|
|
@@ -276,6 +281,19 @@ function isGraphQLUpload(upload) {
|
|
|
276
281
|
function isPromiseLike(obj) {
|
|
277
282
|
return typeof obj.then === 'function';
|
|
278
283
|
}
|
|
284
|
+
var LEGACY_WS;
|
|
285
|
+
(function (LEGACY_WS) {
|
|
286
|
+
LEGACY_WS["CONNECTION_INIT"] = "connection_init";
|
|
287
|
+
LEGACY_WS["CONNECTION_ACK"] = "connection_ack";
|
|
288
|
+
LEGACY_WS["CONNECTION_ERROR"] = "connection_error";
|
|
289
|
+
LEGACY_WS["CONNECTION_KEEP_ALIVE"] = "ka";
|
|
290
|
+
LEGACY_WS["START"] = "start";
|
|
291
|
+
LEGACY_WS["STOP"] = "stop";
|
|
292
|
+
LEGACY_WS["CONNECTION_TERMINATE"] = "connection_terminate";
|
|
293
|
+
LEGACY_WS["DATA"] = "data";
|
|
294
|
+
LEGACY_WS["ERROR"] = "error";
|
|
295
|
+
LEGACY_WS["COMPLETE"] = "complete";
|
|
296
|
+
})(LEGACY_WS || (LEGACY_WS = {}));
|
|
279
297
|
|
|
280
298
|
/* eslint-disable no-case-declarations */
|
|
281
299
|
const asyncImport = (moduleName) => new Promise(function (resolve) { resolve(_interopNamespace(require(moduleName))); });
|
|
@@ -411,23 +429,18 @@ class UrlLoader {
|
|
|
411
429
|
var _a, _b;
|
|
412
430
|
const controller = new crossUndiciFetch.AbortController();
|
|
413
431
|
let method = defaultMethod;
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
432
|
+
const operationAst = utils.getOperationASTFromRequest(request);
|
|
433
|
+
const operationType = operationAst.operation;
|
|
434
|
+
if ((options === null || options === void 0 ? void 0 : options.useGETForQueries) && operationType === 'query') {
|
|
435
|
+
method = 'GET';
|
|
436
|
+
}
|
|
437
|
+
let accept = 'application/json, multipart/mixed';
|
|
438
|
+
if (operationType === 'subscription') {
|
|
439
|
+
method = 'GET';
|
|
440
|
+
accept = 'text/event-stream';
|
|
420
441
|
}
|
|
421
442
|
const endpoint = ((_a = request.extensions) === null || _a === void 0 ? void 0 : _a.endpoint) || HTTP_URL;
|
|
422
443
|
const headers = Object.assign({}, options === null || options === void 0 ? void 0 : options.headers, ((_b = request.extensions) === null || _b === void 0 ? void 0 : _b.headers) || {});
|
|
423
|
-
const acceptedProtocols = [`application/json`];
|
|
424
|
-
if (method === 'GET' && (options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === exports.SubscriptionProtocol.SSE) {
|
|
425
|
-
acceptedProtocols.push('text/event-stream');
|
|
426
|
-
}
|
|
427
|
-
else {
|
|
428
|
-
acceptedProtocols.push('multipart/mixed');
|
|
429
|
-
}
|
|
430
|
-
const accept = acceptedProtocols.join(', ');
|
|
431
444
|
const query = graphql.print(request.document);
|
|
432
445
|
const requestBody = {
|
|
433
446
|
query,
|
|
@@ -509,7 +522,9 @@ class UrlLoader {
|
|
|
509
522
|
})
|
|
510
523
|
.then(result => {
|
|
511
524
|
if (typeof result === 'string') {
|
|
512
|
-
|
|
525
|
+
if (result) {
|
|
526
|
+
return JSON.parse(result);
|
|
527
|
+
}
|
|
513
528
|
}
|
|
514
529
|
else {
|
|
515
530
|
return result;
|
|
@@ -581,43 +596,76 @@ class UrlLoader {
|
|
|
581
596
|
});
|
|
582
597
|
};
|
|
583
598
|
}
|
|
584
|
-
buildWSLegacyExecutor(subscriptionsEndpoint,
|
|
599
|
+
buildWSLegacyExecutor(subscriptionsEndpoint, WebSocketImpl, options) {
|
|
585
600
|
const WS_URL = switchProtocols(subscriptionsEndpoint, {
|
|
586
601
|
https: 'wss',
|
|
587
602
|
http: 'ws',
|
|
588
603
|
});
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
lazy: true,
|
|
592
|
-
}, webSocketImpl);
|
|
593
|
-
return ({ document, variables, operationName, }) => {
|
|
594
|
-
return utils.observableToAsyncIterable(subscriptionClient.request({
|
|
595
|
-
query: document,
|
|
596
|
-
variables,
|
|
597
|
-
operationName,
|
|
598
|
-
}));
|
|
599
|
-
};
|
|
600
|
-
}
|
|
601
|
-
buildGraphQLSSEExecutor(endpoint, fetch, options = {}) {
|
|
602
|
-
const { headers } = options;
|
|
603
|
-
const client = graphqlSse.createClient({
|
|
604
|
-
...options.graphqlSseOptions,
|
|
605
|
-
url: endpoint,
|
|
606
|
-
fetchFn: fetch,
|
|
607
|
-
abortControllerImpl: crossUndiciFetch.AbortController,
|
|
608
|
-
headers,
|
|
609
|
-
});
|
|
610
|
-
return async ({ document, variables, operationName, extensions }) => {
|
|
604
|
+
return function legacyExecutor(request) {
|
|
605
|
+
const id = Date.now().toString();
|
|
611
606
|
return utils.observableToAsyncIterable({
|
|
612
|
-
subscribe
|
|
613
|
-
const
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
}
|
|
607
|
+
subscribe(observer) {
|
|
608
|
+
const websocket = new WebSocketImpl(WS_URL, 'graphql-ws', {
|
|
609
|
+
followRedirects: true,
|
|
610
|
+
headers: options === null || options === void 0 ? void 0 : options.headers,
|
|
611
|
+
rejectUnauthorized: false,
|
|
612
|
+
skipUTF8Validation: true,
|
|
613
|
+
});
|
|
614
|
+
websocket.onopen = () => {
|
|
615
|
+
websocket.send(JSON.stringify({
|
|
616
|
+
type: LEGACY_WS.CONNECTION_INIT,
|
|
617
|
+
payload: {
|
|
618
|
+
...request.extensions,
|
|
619
|
+
},
|
|
620
|
+
}));
|
|
621
|
+
};
|
|
622
|
+
websocket.onmessage = event => {
|
|
623
|
+
const data = JSON.parse(event.data.toString('utf-8'));
|
|
624
|
+
switch (data.type) {
|
|
625
|
+
case LEGACY_WS.CONNECTION_ACK: {
|
|
626
|
+
websocket.send(JSON.stringify({
|
|
627
|
+
type: LEGACY_WS.START,
|
|
628
|
+
id,
|
|
629
|
+
payload: {
|
|
630
|
+
query: graphql.print(request.document),
|
|
631
|
+
variables: request.variables,
|
|
632
|
+
operationName: request.operationName,
|
|
633
|
+
},
|
|
634
|
+
}));
|
|
635
|
+
break;
|
|
636
|
+
}
|
|
637
|
+
case LEGACY_WS.CONNECTION_ERROR: {
|
|
638
|
+
observer.error(data.payload);
|
|
639
|
+
break;
|
|
640
|
+
}
|
|
641
|
+
case LEGACY_WS.CONNECTION_KEEP_ALIVE: {
|
|
642
|
+
break;
|
|
643
|
+
}
|
|
644
|
+
case LEGACY_WS.DATA: {
|
|
645
|
+
observer.next(data.payload);
|
|
646
|
+
break;
|
|
647
|
+
}
|
|
648
|
+
case LEGACY_WS.COMPLETE: {
|
|
649
|
+
websocket.send(JSON.stringify({
|
|
650
|
+
type: LEGACY_WS.CONNECTION_TERMINATE,
|
|
651
|
+
}));
|
|
652
|
+
websocket.terminate();
|
|
653
|
+
observer.complete();
|
|
654
|
+
break;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
};
|
|
619
658
|
return {
|
|
620
|
-
unsubscribe
|
|
659
|
+
unsubscribe: () => {
|
|
660
|
+
websocket.send(JSON.stringify({
|
|
661
|
+
type: LEGACY_WS.STOP,
|
|
662
|
+
id,
|
|
663
|
+
}));
|
|
664
|
+
websocket.send(JSON.stringify({
|
|
665
|
+
type: LEGACY_WS.CONNECTION_TERMINATE,
|
|
666
|
+
}));
|
|
667
|
+
websocket.terminate();
|
|
668
|
+
},
|
|
621
669
|
};
|
|
622
670
|
},
|
|
623
671
|
});
|
|
@@ -662,10 +710,7 @@ class UrlLoader {
|
|
|
662
710
|
}
|
|
663
711
|
buildSubscriptionExecutor(subscriptionsEndpoint, fetch, importFn, options) {
|
|
664
712
|
if ((options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === exports.SubscriptionProtocol.SSE) {
|
|
665
|
-
return this.buildHTTPExecutor(subscriptionsEndpoint, fetch,
|
|
666
|
-
...options,
|
|
667
|
-
method: 'GET',
|
|
668
|
-
});
|
|
713
|
+
return this.buildHTTPExecutor(subscriptionsEndpoint, fetch, options);
|
|
669
714
|
}
|
|
670
715
|
else if ((options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === exports.SubscriptionProtocol.GRAPHQL_SSE) {
|
|
671
716
|
if (!(options === null || options === void 0 ? void 0 : options.subscriptionsEndpoint)) {
|
|
@@ -673,14 +718,14 @@ class UrlLoader {
|
|
|
673
718
|
// graphql-sse is recommended to be used on `/graphql/stream`
|
|
674
719
|
subscriptionsEndpoint += '/stream';
|
|
675
720
|
}
|
|
676
|
-
return this.
|
|
721
|
+
return this.buildHTTPExecutor(subscriptionsEndpoint, fetch, options);
|
|
677
722
|
}
|
|
678
723
|
else {
|
|
679
724
|
const webSocketImpl$ = new valueOrPromise.ValueOrPromise(() => this.getWebSocketImpl(importFn, options));
|
|
680
725
|
const connectionParams = () => ({ headers: options === null || options === void 0 ? void 0 : options.headers });
|
|
681
726
|
const executor$ = webSocketImpl$.then(webSocketImpl => {
|
|
682
727
|
if ((options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === exports.SubscriptionProtocol.LEGACY_WS) {
|
|
683
|
-
return this.buildWSLegacyExecutor(subscriptionsEndpoint, webSocketImpl,
|
|
728
|
+
return this.buildWSLegacyExecutor(subscriptionsEndpoint, webSocketImpl, options);
|
|
684
729
|
}
|
|
685
730
|
else {
|
|
686
731
|
return this.buildWSExecutor(subscriptionsEndpoint, webSocketImpl, connectionParams);
|
package/index.mjs
CHANGED
|
@@ -2,13 +2,11 @@ import { print, buildASTSchema, buildSchema } from 'graphql';
|
|
|
2
2
|
import { mapAsyncIterator, isAsyncIterable, inspect, withCancel, observableToAsyncIterable, parseGraphQLSDL, getOperationASTFromRequest } from '@graphql-tools/utils';
|
|
3
3
|
import { introspectSchema, wrapSchema } from '@graphql-tools/wrap';
|
|
4
4
|
import { createClient } from 'graphql-ws';
|
|
5
|
-
import { createClient as createClient$1 } from 'graphql-sse';
|
|
6
5
|
import WebSocket from 'isomorphic-ws';
|
|
7
6
|
import { extractFiles, isExtractableFile } from 'extract-files';
|
|
8
|
-
import { SubscriptionClient } from 'subscriptions-transport-ws';
|
|
9
7
|
import { ValueOrPromise } from 'value-or-promise';
|
|
10
8
|
import { isLiveQueryOperationDefinitionNode } from '@n1ru4l/graphql-live-query';
|
|
11
|
-
import { fetch, FormData,
|
|
9
|
+
import { fetch, FormData, File, AbortController } from 'cross-undici-fetch';
|
|
12
10
|
import syncFetchImported from 'sync-fetch';
|
|
13
11
|
import { meros } from 'meros/node';
|
|
14
12
|
import { meros as meros$1 } from 'meros/browser';
|
|
@@ -74,10 +72,17 @@ async function handleMultipartMixedResponse(response) {
|
|
|
74
72
|
}
|
|
75
73
|
|
|
76
74
|
/* eslint-disable no-labels */
|
|
75
|
+
let decodeUint8Array;
|
|
76
|
+
if (globalThis.Buffer) {
|
|
77
|
+
decodeUint8Array = uint8Array => globalThis.Buffer.from(uint8Array).toString('utf-8');
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
const textDecoder = new TextDecoder();
|
|
81
|
+
decodeUint8Array = uint8Array => textDecoder.decode(uint8Array);
|
|
82
|
+
}
|
|
77
83
|
async function* handleReadable(readable) {
|
|
78
|
-
const decoder = new TextDecoder();
|
|
79
84
|
outer: for await (const chunk of readable) {
|
|
80
|
-
const chunkStr = typeof chunk === 'string' ? chunk :
|
|
85
|
+
const chunkStr = typeof chunk === 'string' ? chunk : decodeUint8Array(chunk);
|
|
81
86
|
for (const part of chunkStr.split('\n\n')) {
|
|
82
87
|
if (part) {
|
|
83
88
|
const eventStr = part.split('event: ')[1];
|
|
@@ -251,6 +256,19 @@ function isGraphQLUpload(upload) {
|
|
|
251
256
|
function isPromiseLike(obj) {
|
|
252
257
|
return typeof obj.then === 'function';
|
|
253
258
|
}
|
|
259
|
+
var LEGACY_WS;
|
|
260
|
+
(function (LEGACY_WS) {
|
|
261
|
+
LEGACY_WS["CONNECTION_INIT"] = "connection_init";
|
|
262
|
+
LEGACY_WS["CONNECTION_ACK"] = "connection_ack";
|
|
263
|
+
LEGACY_WS["CONNECTION_ERROR"] = "connection_error";
|
|
264
|
+
LEGACY_WS["CONNECTION_KEEP_ALIVE"] = "ka";
|
|
265
|
+
LEGACY_WS["START"] = "start";
|
|
266
|
+
LEGACY_WS["STOP"] = "stop";
|
|
267
|
+
LEGACY_WS["CONNECTION_TERMINATE"] = "connection_terminate";
|
|
268
|
+
LEGACY_WS["DATA"] = "data";
|
|
269
|
+
LEGACY_WS["ERROR"] = "error";
|
|
270
|
+
LEGACY_WS["COMPLETE"] = "complete";
|
|
271
|
+
})(LEGACY_WS || (LEGACY_WS = {}));
|
|
254
272
|
|
|
255
273
|
/* eslint-disable no-case-declarations */
|
|
256
274
|
const asyncImport = (moduleName) => import(moduleName);
|
|
@@ -387,23 +405,18 @@ class UrlLoader {
|
|
|
387
405
|
var _a, _b;
|
|
388
406
|
const controller = new AbortController();
|
|
389
407
|
let method = defaultMethod;
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
408
|
+
const operationAst = getOperationASTFromRequest(request);
|
|
409
|
+
const operationType = operationAst.operation;
|
|
410
|
+
if ((options === null || options === void 0 ? void 0 : options.useGETForQueries) && operationType === 'query') {
|
|
411
|
+
method = 'GET';
|
|
412
|
+
}
|
|
413
|
+
let accept = 'application/json, multipart/mixed';
|
|
414
|
+
if (operationType === 'subscription') {
|
|
415
|
+
method = 'GET';
|
|
416
|
+
accept = 'text/event-stream';
|
|
396
417
|
}
|
|
397
418
|
const endpoint = ((_a = request.extensions) === null || _a === void 0 ? void 0 : _a.endpoint) || HTTP_URL;
|
|
398
419
|
const headers = Object.assign({}, options === null || options === void 0 ? void 0 : options.headers, ((_b = request.extensions) === null || _b === void 0 ? void 0 : _b.headers) || {});
|
|
399
|
-
const acceptedProtocols = [`application/json`];
|
|
400
|
-
if (method === 'GET' && (options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === SubscriptionProtocol.SSE) {
|
|
401
|
-
acceptedProtocols.push('text/event-stream');
|
|
402
|
-
}
|
|
403
|
-
else {
|
|
404
|
-
acceptedProtocols.push('multipart/mixed');
|
|
405
|
-
}
|
|
406
|
-
const accept = acceptedProtocols.join(', ');
|
|
407
420
|
const query = print(request.document);
|
|
408
421
|
const requestBody = {
|
|
409
422
|
query,
|
|
@@ -485,7 +498,9 @@ class UrlLoader {
|
|
|
485
498
|
})
|
|
486
499
|
.then(result => {
|
|
487
500
|
if (typeof result === 'string') {
|
|
488
|
-
|
|
501
|
+
if (result) {
|
|
502
|
+
return JSON.parse(result);
|
|
503
|
+
}
|
|
489
504
|
}
|
|
490
505
|
else {
|
|
491
506
|
return result;
|
|
@@ -557,43 +572,76 @@ class UrlLoader {
|
|
|
557
572
|
});
|
|
558
573
|
};
|
|
559
574
|
}
|
|
560
|
-
buildWSLegacyExecutor(subscriptionsEndpoint,
|
|
575
|
+
buildWSLegacyExecutor(subscriptionsEndpoint, WebSocketImpl, options) {
|
|
561
576
|
const WS_URL = switchProtocols(subscriptionsEndpoint, {
|
|
562
577
|
https: 'wss',
|
|
563
578
|
http: 'ws',
|
|
564
579
|
});
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
lazy: true,
|
|
568
|
-
}, webSocketImpl);
|
|
569
|
-
return ({ document, variables, operationName, }) => {
|
|
570
|
-
return observableToAsyncIterable(subscriptionClient.request({
|
|
571
|
-
query: document,
|
|
572
|
-
variables,
|
|
573
|
-
operationName,
|
|
574
|
-
}));
|
|
575
|
-
};
|
|
576
|
-
}
|
|
577
|
-
buildGraphQLSSEExecutor(endpoint, fetch, options = {}) {
|
|
578
|
-
const { headers } = options;
|
|
579
|
-
const client = createClient$1({
|
|
580
|
-
...options.graphqlSseOptions,
|
|
581
|
-
url: endpoint,
|
|
582
|
-
fetchFn: fetch,
|
|
583
|
-
abortControllerImpl: AbortController,
|
|
584
|
-
headers,
|
|
585
|
-
});
|
|
586
|
-
return async ({ document, variables, operationName, extensions }) => {
|
|
580
|
+
return function legacyExecutor(request) {
|
|
581
|
+
const id = Date.now().toString();
|
|
587
582
|
return observableToAsyncIterable({
|
|
588
|
-
subscribe
|
|
589
|
-
const
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
}
|
|
583
|
+
subscribe(observer) {
|
|
584
|
+
const websocket = new WebSocketImpl(WS_URL, 'graphql-ws', {
|
|
585
|
+
followRedirects: true,
|
|
586
|
+
headers: options === null || options === void 0 ? void 0 : options.headers,
|
|
587
|
+
rejectUnauthorized: false,
|
|
588
|
+
skipUTF8Validation: true,
|
|
589
|
+
});
|
|
590
|
+
websocket.onopen = () => {
|
|
591
|
+
websocket.send(JSON.stringify({
|
|
592
|
+
type: LEGACY_WS.CONNECTION_INIT,
|
|
593
|
+
payload: {
|
|
594
|
+
...request.extensions,
|
|
595
|
+
},
|
|
596
|
+
}));
|
|
597
|
+
};
|
|
598
|
+
websocket.onmessage = event => {
|
|
599
|
+
const data = JSON.parse(event.data.toString('utf-8'));
|
|
600
|
+
switch (data.type) {
|
|
601
|
+
case LEGACY_WS.CONNECTION_ACK: {
|
|
602
|
+
websocket.send(JSON.stringify({
|
|
603
|
+
type: LEGACY_WS.START,
|
|
604
|
+
id,
|
|
605
|
+
payload: {
|
|
606
|
+
query: print(request.document),
|
|
607
|
+
variables: request.variables,
|
|
608
|
+
operationName: request.operationName,
|
|
609
|
+
},
|
|
610
|
+
}));
|
|
611
|
+
break;
|
|
612
|
+
}
|
|
613
|
+
case LEGACY_WS.CONNECTION_ERROR: {
|
|
614
|
+
observer.error(data.payload);
|
|
615
|
+
break;
|
|
616
|
+
}
|
|
617
|
+
case LEGACY_WS.CONNECTION_KEEP_ALIVE: {
|
|
618
|
+
break;
|
|
619
|
+
}
|
|
620
|
+
case LEGACY_WS.DATA: {
|
|
621
|
+
observer.next(data.payload);
|
|
622
|
+
break;
|
|
623
|
+
}
|
|
624
|
+
case LEGACY_WS.COMPLETE: {
|
|
625
|
+
websocket.send(JSON.stringify({
|
|
626
|
+
type: LEGACY_WS.CONNECTION_TERMINATE,
|
|
627
|
+
}));
|
|
628
|
+
websocket.terminate();
|
|
629
|
+
observer.complete();
|
|
630
|
+
break;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
};
|
|
595
634
|
return {
|
|
596
|
-
unsubscribe
|
|
635
|
+
unsubscribe: () => {
|
|
636
|
+
websocket.send(JSON.stringify({
|
|
637
|
+
type: LEGACY_WS.STOP,
|
|
638
|
+
id,
|
|
639
|
+
}));
|
|
640
|
+
websocket.send(JSON.stringify({
|
|
641
|
+
type: LEGACY_WS.CONNECTION_TERMINATE,
|
|
642
|
+
}));
|
|
643
|
+
websocket.terminate();
|
|
644
|
+
},
|
|
597
645
|
};
|
|
598
646
|
},
|
|
599
647
|
});
|
|
@@ -638,10 +686,7 @@ class UrlLoader {
|
|
|
638
686
|
}
|
|
639
687
|
buildSubscriptionExecutor(subscriptionsEndpoint, fetch, importFn, options) {
|
|
640
688
|
if ((options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === SubscriptionProtocol.SSE) {
|
|
641
|
-
return this.buildHTTPExecutor(subscriptionsEndpoint, fetch,
|
|
642
|
-
...options,
|
|
643
|
-
method: 'GET',
|
|
644
|
-
});
|
|
689
|
+
return this.buildHTTPExecutor(subscriptionsEndpoint, fetch, options);
|
|
645
690
|
}
|
|
646
691
|
else if ((options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === SubscriptionProtocol.GRAPHQL_SSE) {
|
|
647
692
|
if (!(options === null || options === void 0 ? void 0 : options.subscriptionsEndpoint)) {
|
|
@@ -649,14 +694,14 @@ class UrlLoader {
|
|
|
649
694
|
// graphql-sse is recommended to be used on `/graphql/stream`
|
|
650
695
|
subscriptionsEndpoint += '/stream';
|
|
651
696
|
}
|
|
652
|
-
return this.
|
|
697
|
+
return this.buildHTTPExecutor(subscriptionsEndpoint, fetch, options);
|
|
653
698
|
}
|
|
654
699
|
else {
|
|
655
700
|
const webSocketImpl$ = new ValueOrPromise(() => this.getWebSocketImpl(importFn, options));
|
|
656
701
|
const connectionParams = () => ({ headers: options === null || options === void 0 ? void 0 : options.headers });
|
|
657
702
|
const executor$ = webSocketImpl$.then(webSocketImpl => {
|
|
658
703
|
if ((options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === SubscriptionProtocol.LEGACY_WS) {
|
|
659
|
-
return this.buildWSLegacyExecutor(subscriptionsEndpoint, webSocketImpl,
|
|
704
|
+
return this.buildWSLegacyExecutor(subscriptionsEndpoint, webSocketImpl, options);
|
|
660
705
|
}
|
|
661
706
|
else {
|
|
662
707
|
return this.buildWSExecutor(subscriptionsEndpoint, webSocketImpl, connectionParams);
|
package/package.json
CHANGED
|
@@ -1,28 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/url-loader",
|
|
3
|
-
"version": "7.9.
|
|
3
|
+
"version": "7.9.13",
|
|
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
|
-
"@
|
|
11
|
-
"@graphql-tools/
|
|
12
|
-
"@graphql-tools/
|
|
13
|
-
"@graphql-
|
|
14
|
-
"@graphql-yoga/node": "2.2.1",
|
|
10
|
+
"@graphql-tools/delegate": "8.7.6",
|
|
11
|
+
"@graphql-tools/utils": "8.6.8",
|
|
12
|
+
"@graphql-tools/wrap": "8.4.15",
|
|
13
|
+
"@graphql-yoga/node": "2.3.0",
|
|
15
14
|
"@n1ru4l/graphql-live-query": "^0.9.0",
|
|
16
|
-
"@types/websocket": "^1.0.4",
|
|
17
15
|
"@types/ws": "^8.0.0",
|
|
18
16
|
"cross-undici-fetch": "^0.2.4",
|
|
19
17
|
"dset": "^3.1.0",
|
|
20
18
|
"extract-files": "^11.0.0",
|
|
21
|
-
"graphql-sse": "^1.0.1",
|
|
22
19
|
"graphql-ws": "^5.4.1",
|
|
23
20
|
"isomorphic-ws": "^4.0.1",
|
|
24
21
|
"meros": "^1.1.4",
|
|
25
|
-
"subscriptions-transport-ws": "^0.11.0",
|
|
26
22
|
"sync-fetch": "^0.3.1",
|
|
27
23
|
"tslib": "^2.3.0",
|
|
28
24
|
"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 {};
|