@graphql-tools/url-loader 7.8.0 → 7.9.2
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 +9 -8
- package/index.js +64 -46
- package/index.mjs +65 -47
- package/package.json +2 -3
package/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="ws" />
|
|
2
2
|
/// <reference lib="dom" />
|
|
3
3
|
import { IntrospectionOptions } from 'graphql';
|
|
4
|
-
import { AsyncExecutor, SyncExecutor, Source, Loader, BaseLoaderOptions } from '@graphql-tools/utils';
|
|
4
|
+
import { AsyncExecutor, Executor, SyncExecutor, Source, Loader, BaseLoaderOptions } from '@graphql-tools/utils';
|
|
5
5
|
import { ClientOptions } from 'graphql-ws';
|
|
6
6
|
import { ClientOptions as GraphQLSSEClientOptions } from 'graphql-sse';
|
|
7
7
|
import WebSocket from 'isomorphic-ws';
|
|
@@ -107,8 +107,6 @@ export interface LoadFromUrlOptions extends BaseLoaderOptions, Partial<Introspec
|
|
|
107
107
|
* ```
|
|
108
108
|
*/
|
|
109
109
|
export declare class UrlLoader implements Loader<LoadFromUrlOptions> {
|
|
110
|
-
canLoad(pointer: string, options: LoadFromUrlOptions): Promise<boolean>;
|
|
111
|
-
canLoadSync(pointer: string, _options: LoadFromUrlOptions): boolean;
|
|
112
110
|
createFormDataFromVariables<TVariables>({ query, variables, operationName, extensions, }: {
|
|
113
111
|
query: string;
|
|
114
112
|
variables: TVariables;
|
|
@@ -124,17 +122,20 @@ export declare class UrlLoader implements Loader<LoadFromUrlOptions> {
|
|
|
124
122
|
}): string;
|
|
125
123
|
buildHTTPExecutor(endpoint: string, fetch: SyncFetchFn, options?: LoadFromUrlOptions): SyncExecutor<any, ExecutionExtensions>;
|
|
126
124
|
buildHTTPExecutor(endpoint: string, fetch: AsyncFetchFn, options?: LoadFromUrlOptions): AsyncExecutor<any, ExecutionExtensions>;
|
|
127
|
-
buildWSExecutor(subscriptionsEndpoint: string, webSocketImpl: typeof WebSocket, connectionParams?: ClientOptions['connectionParams']):
|
|
128
|
-
buildWSLegacyExecutor(subscriptionsEndpoint: string, webSocketImpl: typeof WebSocket, connectionParams?: ConnectionParamsOptions):
|
|
125
|
+
buildWSExecutor(subscriptionsEndpoint: string, webSocketImpl: typeof WebSocket, connectionParams?: ClientOptions['connectionParams']): Executor;
|
|
126
|
+
buildWSLegacyExecutor(subscriptionsEndpoint: string, webSocketImpl: typeof WebSocket, connectionParams?: ConnectionParamsOptions): Executor;
|
|
129
127
|
buildGraphQLSSEExecutor(endpoint: string, fetch: AsyncFetchFn, options?: Omit<LoadFromUrlOptions, 'subscriptionEndpoint'>): AsyncExecutor;
|
|
130
128
|
getFetch(customFetch: LoadFromUrlOptions['customFetch'], importFn: AsyncImportFn): PromiseLike<AsyncFetchFn> | AsyncFetchFn;
|
|
131
129
|
getFetch(customFetch: LoadFromUrlOptions['customFetch'], importFn: SyncImportFn): SyncFetchFn;
|
|
132
130
|
private getDefaultMethodFromOptions;
|
|
133
131
|
getWebSocketImpl(importFn: AsyncImportFn, options?: LoadFromUrlOptions): PromiseLike<typeof WebSocket>;
|
|
134
132
|
getWebSocketImpl(importFn: SyncImportFn, options?: LoadFromUrlOptions): typeof WebSocket;
|
|
135
|
-
buildSubscriptionExecutor(subscriptionsEndpoint: string, fetch:
|
|
136
|
-
|
|
137
|
-
|
|
133
|
+
buildSubscriptionExecutor(subscriptionsEndpoint: string, fetch: SyncFetchFn, syncImport: SyncImportFn, options?: LoadFromUrlOptions): SyncExecutor;
|
|
134
|
+
buildSubscriptionExecutor(subscriptionsEndpoint: string, fetch: AsyncFetchFn, asyncImport: AsyncImportFn, options?: LoadFromUrlOptions): Promise<AsyncExecutor> | AsyncExecutor;
|
|
135
|
+
getExecutor(endpoint: string, asyncImport: AsyncImportFn, options?: Omit<LoadFromUrlOptions, 'endpoint'>): AsyncExecutor;
|
|
136
|
+
getExecutor(endpoint: string, syncImport: SyncImportFn, options?: Omit<LoadFromUrlOptions, 'endpoint'>): SyncExecutor;
|
|
137
|
+
getExecutorAsync(endpoint: string, options?: Omit<LoadFromUrlOptions, 'endpoint'>): AsyncExecutor;
|
|
138
|
+
getExecutorSync(endpoint: string, options?: Omit<LoadFromUrlOptions, 'endpoint'>): SyncExecutor;
|
|
138
139
|
handleSDL(pointer: string, fetch: SyncFetchFn, options: LoadFromUrlOptions): Source;
|
|
139
140
|
handleSDL(pointer: string, fetch: AsyncFetchFn, options: LoadFromUrlOptions): Promise<Source>;
|
|
140
141
|
load(pointer: string, options: LoadFromUrlOptions): Promise<Source[]>;
|
package/index.js
CHANGED
|
@@ -25,7 +25,6 @@ function _interopNamespace(e) {
|
|
|
25
25
|
|
|
26
26
|
const graphql = require('graphql');
|
|
27
27
|
const utils = require('@graphql-tools/utils');
|
|
28
|
-
const validUrl = require('valid-url');
|
|
29
28
|
const wrap = require('@graphql-tools/wrap');
|
|
30
29
|
const graphqlWs = require('graphql-ws');
|
|
31
30
|
const graphqlSse = require('graphql-sse');
|
|
@@ -296,14 +295,16 @@ const syncImport = (moduleName) => require(moduleName);
|
|
|
296
295
|
*/
|
|
297
296
|
SubscriptionProtocol["GRAPHQL_SSE"] = "GRAPHQL_SSE";
|
|
298
297
|
})(exports.SubscriptionProtocol || (exports.SubscriptionProtocol = {}));
|
|
299
|
-
|
|
300
|
-
|
|
298
|
+
function isCompatibleUri(uri) {
|
|
299
|
+
try {
|
|
300
|
+
// eslint-disable-next-line no-new
|
|
301
|
+
new URL(uri);
|
|
301
302
|
return true;
|
|
302
303
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
304
|
+
catch (_a) {
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
307
308
|
/**
|
|
308
309
|
* This loader loads a schema from a URL. The loaded schema is a fully-executable,
|
|
309
310
|
* remote schema since it's created using [@graphql-tools/wrap](/docs/remote-schemas).
|
|
@@ -317,12 +318,6 @@ const isCompatibleUri = (uri) => {
|
|
|
317
318
|
* ```
|
|
318
319
|
*/
|
|
319
320
|
class UrlLoader {
|
|
320
|
-
async canLoad(pointer, options) {
|
|
321
|
-
return this.canLoadSync(pointer, options);
|
|
322
|
-
}
|
|
323
|
-
canLoadSync(pointer, _options) {
|
|
324
|
-
return isCompatibleUri(pointer);
|
|
325
|
-
}
|
|
326
321
|
createFormDataFromVariables({ query, variables, operationName, extensions, }) {
|
|
327
322
|
const vars = Object.assign({}, variables);
|
|
328
323
|
const { clone, files } = extractFiles.extractFiles(vars, 'variables', ((v) => extractFiles.isExtractableFile(v) ||
|
|
@@ -423,7 +418,7 @@ class UrlLoader {
|
|
|
423
418
|
method = 'GET';
|
|
424
419
|
}
|
|
425
420
|
}
|
|
426
|
-
const endpoint = ((_a = request.extensions) === null || _a === void 0 ? void 0 : _a.endpoint) ||
|
|
421
|
+
const endpoint = ((_a = request.extensions) === null || _a === void 0 ? void 0 : _a.endpoint) || HTTP_URL;
|
|
427
422
|
const headers = Object.assign({}, options === null || options === void 0 ? void 0 : options.headers, ((_b = request.extensions) === null || _b === void 0 ? void 0 : _b.headers) || {});
|
|
428
423
|
const acceptedProtocols = [`application/json`];
|
|
429
424
|
if (method === 'GET' && (options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === exports.SubscriptionProtocol.SSE) {
|
|
@@ -468,7 +463,7 @@ class UrlLoader {
|
|
|
468
463
|
case 'POST':
|
|
469
464
|
if (options === null || options === void 0 ? void 0 : options.multipart) {
|
|
470
465
|
return new valueOrPromise.ValueOrPromise(() => this.createFormDataFromVariables(requestBody))
|
|
471
|
-
.then(form => fetch(
|
|
466
|
+
.then(form => fetch(endpoint, {
|
|
472
467
|
method: 'POST',
|
|
473
468
|
credentials,
|
|
474
469
|
body: form,
|
|
@@ -481,7 +476,7 @@ class UrlLoader {
|
|
|
481
476
|
.resolve();
|
|
482
477
|
}
|
|
483
478
|
else {
|
|
484
|
-
return fetch(
|
|
479
|
+
return fetch(endpoint, {
|
|
485
480
|
method: 'POST',
|
|
486
481
|
credentials,
|
|
487
482
|
body: JSON.stringify(requestBody),
|
|
@@ -510,7 +505,15 @@ class UrlLoader {
|
|
|
510
505
|
else if (contentType === null || contentType === void 0 ? void 0 : contentType.includes('multipart/mixed')) {
|
|
511
506
|
return handleMultipartMixedResponse(fetchResult).then(resultStream => addCancelToResponseStream(resultStream, controller));
|
|
512
507
|
}
|
|
513
|
-
return fetchResult.
|
|
508
|
+
return fetchResult.text();
|
|
509
|
+
})
|
|
510
|
+
.then(result => {
|
|
511
|
+
if (typeof result === 'string') {
|
|
512
|
+
return JSON.parse(result);
|
|
513
|
+
}
|
|
514
|
+
else {
|
|
515
|
+
return result;
|
|
516
|
+
}
|
|
514
517
|
})
|
|
515
518
|
.resolve();
|
|
516
519
|
};
|
|
@@ -561,7 +564,7 @@ class UrlLoader {
|
|
|
561
564
|
connectionParams,
|
|
562
565
|
lazy: true,
|
|
563
566
|
});
|
|
564
|
-
return
|
|
567
|
+
return ({ document, variables, operationName, extensions }) => {
|
|
565
568
|
const query = graphql.print(document);
|
|
566
569
|
return utils.observableToAsyncIterable({
|
|
567
570
|
subscribe: observer => {
|
|
@@ -587,7 +590,7 @@ class UrlLoader {
|
|
|
587
590
|
connectionParams,
|
|
588
591
|
lazy: true,
|
|
589
592
|
}, webSocketImpl);
|
|
590
|
-
return
|
|
593
|
+
return ({ document, variables, operationName }) => {
|
|
591
594
|
return utils.observableToAsyncIterable(subscriptionClient.request({
|
|
592
595
|
query: document,
|
|
593
596
|
variables,
|
|
@@ -657,7 +660,7 @@ class UrlLoader {
|
|
|
657
660
|
return websocketImpl;
|
|
658
661
|
}
|
|
659
662
|
}
|
|
660
|
-
|
|
663
|
+
buildSubscriptionExecutor(subscriptionsEndpoint, fetch, importFn, options) {
|
|
661
664
|
if ((options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === exports.SubscriptionProtocol.SSE) {
|
|
662
665
|
return this.buildHTTPExecutor(subscriptionsEndpoint, fetch, {
|
|
663
666
|
...options,
|
|
@@ -673,34 +676,47 @@ class UrlLoader {
|
|
|
673
676
|
return this.buildGraphQLSSEExecutor(subscriptionsEndpoint, fetch, options);
|
|
674
677
|
}
|
|
675
678
|
else {
|
|
676
|
-
const webSocketImpl =
|
|
679
|
+
const webSocketImpl$ = new valueOrPromise.ValueOrPromise(() => this.getWebSocketImpl(importFn, options));
|
|
677
680
|
const connectionParams = () => ({ headers: options === null || options === void 0 ? void 0 : options.headers });
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
681
|
+
const executor$ = webSocketImpl$.then(webSocketImpl => {
|
|
682
|
+
if ((options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === exports.SubscriptionProtocol.LEGACY_WS) {
|
|
683
|
+
return this.buildWSLegacyExecutor(subscriptionsEndpoint, webSocketImpl, connectionParams);
|
|
684
|
+
}
|
|
685
|
+
else {
|
|
686
|
+
return this.buildWSExecutor(subscriptionsEndpoint, webSocketImpl, connectionParams);
|
|
687
|
+
}
|
|
688
|
+
});
|
|
689
|
+
return request => executor$.then(executor => executor(request)).resolve();
|
|
684
690
|
}
|
|
685
691
|
}
|
|
686
|
-
|
|
687
|
-
const fetch =
|
|
688
|
-
const httpExecutor =
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
+
getExecutor(endpoint, importFn, options) {
|
|
693
|
+
const fetch$ = new valueOrPromise.ValueOrPromise(() => this.getFetch(options === null || options === void 0 ? void 0 : options.customFetch, asyncImport));
|
|
694
|
+
const httpExecutor$ = fetch$.then(fetch => {
|
|
695
|
+
return this.buildHTTPExecutor(endpoint, fetch, options);
|
|
696
|
+
});
|
|
697
|
+
const subscriptionExecutor$ = fetch$.then(fetch => {
|
|
698
|
+
const subscriptionsEndpoint = (options === null || options === void 0 ? void 0 : options.subscriptionsEndpoint) || endpoint;
|
|
699
|
+
return this.buildSubscriptionExecutor(subscriptionsEndpoint, fetch, importFn, options);
|
|
700
|
+
});
|
|
701
|
+
function getExecutorByRequest(request) {
|
|
692
702
|
const operationAst = utils.getOperationASTFromRequest(request);
|
|
693
703
|
if (operationAst.operation === 'subscription' ||
|
|
694
704
|
graphqlLiveQuery.isLiveQueryOperationDefinitionNode(operationAst, request.variables)) {
|
|
695
|
-
return subscriptionExecutor
|
|
705
|
+
return subscriptionExecutor$;
|
|
696
706
|
}
|
|
697
|
-
|
|
698
|
-
|
|
707
|
+
else {
|
|
708
|
+
return httpExecutor$;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
return request => getExecutorByRequest(request)
|
|
712
|
+
.then(executor => executor(request))
|
|
713
|
+
.resolve();
|
|
714
|
+
}
|
|
715
|
+
getExecutorAsync(endpoint, options) {
|
|
716
|
+
return this.getExecutor(endpoint, asyncImport, options);
|
|
699
717
|
}
|
|
700
718
|
getExecutorSync(endpoint, options) {
|
|
701
|
-
|
|
702
|
-
const executor = this.buildHTTPExecutor(endpoint, fetch, options);
|
|
703
|
-
return executor;
|
|
719
|
+
return this.getExecutor(endpoint, syncImport, options);
|
|
704
720
|
}
|
|
705
721
|
handleSDL(pointer, fetch, options) {
|
|
706
722
|
const defaultMethod = this.getDefaultMethodFromOptions(options === null || options === void 0 ? void 0 : options.method, 'GET');
|
|
@@ -713,15 +729,15 @@ class UrlLoader {
|
|
|
713
729
|
.resolve();
|
|
714
730
|
}
|
|
715
731
|
async load(pointer, options) {
|
|
716
|
-
if (!(
|
|
732
|
+
if (!isCompatibleUri(pointer)) {
|
|
717
733
|
return [];
|
|
718
734
|
}
|
|
719
735
|
let source = {
|
|
720
736
|
location: pointer,
|
|
721
737
|
};
|
|
722
|
-
|
|
723
|
-
let executor = await this.getExecutorAsync(pointer, options);
|
|
738
|
+
let executor;
|
|
724
739
|
if ((options === null || options === void 0 ? void 0 : options.handleAsSDL) || pointer.endsWith('.graphql') || pointer.endsWith('.graphqls')) {
|
|
740
|
+
const fetch = await this.getFetch(options === null || options === void 0 ? void 0 : options.customFetch, asyncImport);
|
|
725
741
|
source = await this.handleSDL(pointer, fetch, options);
|
|
726
742
|
if (!source.schema && !source.document && !source.rawSDL) {
|
|
727
743
|
throw new Error(`Invalid SDL response`);
|
|
@@ -735,13 +751,14 @@ class UrlLoader {
|
|
|
735
751
|
: undefined);
|
|
736
752
|
}
|
|
737
753
|
else {
|
|
754
|
+
executor = this.getExecutorAsync(pointer, options);
|
|
738
755
|
source.schema = await wrap.introspectSchema(executor, {}, options);
|
|
739
756
|
}
|
|
740
757
|
if (!source.schema) {
|
|
741
758
|
throw new Error(`Invalid introspected schema`);
|
|
742
759
|
}
|
|
743
760
|
if (options === null || options === void 0 ? void 0 : options.endpoint) {
|
|
744
|
-
executor =
|
|
761
|
+
executor = this.getExecutorAsync(options.endpoint, options);
|
|
745
762
|
}
|
|
746
763
|
source.schema = wrap.wrapSchema({
|
|
747
764
|
schema: source.schema,
|
|
@@ -750,15 +767,15 @@ class UrlLoader {
|
|
|
750
767
|
return [source];
|
|
751
768
|
}
|
|
752
769
|
loadSync(pointer, options) {
|
|
753
|
-
if (!
|
|
770
|
+
if (!isCompatibleUri(pointer)) {
|
|
754
771
|
return [];
|
|
755
772
|
}
|
|
756
773
|
let source = {
|
|
757
774
|
location: pointer,
|
|
758
775
|
};
|
|
759
|
-
|
|
760
|
-
let executor = this.getExecutorSync(pointer, options);
|
|
776
|
+
let executor;
|
|
761
777
|
if ((options === null || options === void 0 ? void 0 : options.handleAsSDL) || pointer.endsWith('.graphql') || pointer.endsWith('.graphqls')) {
|
|
778
|
+
const fetch = this.getFetch(options === null || options === void 0 ? void 0 : options.customFetch, syncImport);
|
|
762
779
|
source = this.handleSDL(pointer, fetch, options);
|
|
763
780
|
if (!source.schema && !source.document && !source.rawSDL) {
|
|
764
781
|
throw new Error(`Invalid SDL response`);
|
|
@@ -772,6 +789,7 @@ class UrlLoader {
|
|
|
772
789
|
: undefined);
|
|
773
790
|
}
|
|
774
791
|
else {
|
|
792
|
+
executor = this.getExecutorSync(pointer, options);
|
|
775
793
|
source.schema = wrap.introspectSchema(executor, {}, options);
|
|
776
794
|
}
|
|
777
795
|
if (!source.schema) {
|
package/index.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { print, buildASTSchema, buildSchema } from 'graphql';
|
|
2
|
-
import { mapAsyncIterator, isAsyncIterable, inspect, withCancel, observableToAsyncIterable,
|
|
3
|
-
import { isWebUri } from 'valid-url';
|
|
2
|
+
import { mapAsyncIterator, isAsyncIterable, inspect, withCancel, observableToAsyncIterable, parseGraphQLSDL, getOperationASTFromRequest } from '@graphql-tools/utils';
|
|
4
3
|
import { introspectSchema, wrapSchema } from '@graphql-tools/wrap';
|
|
5
4
|
import { createClient } from 'graphql-ws';
|
|
6
5
|
import { createClient as createClient$1 } from 'graphql-sse';
|
|
@@ -272,14 +271,16 @@ var SubscriptionProtocol;
|
|
|
272
271
|
*/
|
|
273
272
|
SubscriptionProtocol["GRAPHQL_SSE"] = "GRAPHQL_SSE";
|
|
274
273
|
})(SubscriptionProtocol || (SubscriptionProtocol = {}));
|
|
275
|
-
|
|
276
|
-
|
|
274
|
+
function isCompatibleUri(uri) {
|
|
275
|
+
try {
|
|
276
|
+
// eslint-disable-next-line no-new
|
|
277
|
+
new URL(uri);
|
|
277
278
|
return true;
|
|
278
279
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
280
|
+
catch (_a) {
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
283
284
|
/**
|
|
284
285
|
* This loader loads a schema from a URL. The loaded schema is a fully-executable,
|
|
285
286
|
* remote schema since it's created using [@graphql-tools/wrap](/docs/remote-schemas).
|
|
@@ -293,12 +294,6 @@ const isCompatibleUri = (uri) => {
|
|
|
293
294
|
* ```
|
|
294
295
|
*/
|
|
295
296
|
class UrlLoader {
|
|
296
|
-
async canLoad(pointer, options) {
|
|
297
|
-
return this.canLoadSync(pointer, options);
|
|
298
|
-
}
|
|
299
|
-
canLoadSync(pointer, _options) {
|
|
300
|
-
return isCompatibleUri(pointer);
|
|
301
|
-
}
|
|
302
297
|
createFormDataFromVariables({ query, variables, operationName, extensions, }) {
|
|
303
298
|
const vars = Object.assign({}, variables);
|
|
304
299
|
const { clone, files } = extractFiles(vars, 'variables', ((v) => isExtractableFile(v) ||
|
|
@@ -399,7 +394,7 @@ class UrlLoader {
|
|
|
399
394
|
method = 'GET';
|
|
400
395
|
}
|
|
401
396
|
}
|
|
402
|
-
const endpoint = ((_a = request.extensions) === null || _a === void 0 ? void 0 : _a.endpoint) ||
|
|
397
|
+
const endpoint = ((_a = request.extensions) === null || _a === void 0 ? void 0 : _a.endpoint) || HTTP_URL;
|
|
403
398
|
const headers = Object.assign({}, options === null || options === void 0 ? void 0 : options.headers, ((_b = request.extensions) === null || _b === void 0 ? void 0 : _b.headers) || {});
|
|
404
399
|
const acceptedProtocols = [`application/json`];
|
|
405
400
|
if (method === 'GET' && (options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === SubscriptionProtocol.SSE) {
|
|
@@ -444,7 +439,7 @@ class UrlLoader {
|
|
|
444
439
|
case 'POST':
|
|
445
440
|
if (options === null || options === void 0 ? void 0 : options.multipart) {
|
|
446
441
|
return new ValueOrPromise(() => this.createFormDataFromVariables(requestBody))
|
|
447
|
-
.then(form => fetch(
|
|
442
|
+
.then(form => fetch(endpoint, {
|
|
448
443
|
method: 'POST',
|
|
449
444
|
credentials,
|
|
450
445
|
body: form,
|
|
@@ -457,7 +452,7 @@ class UrlLoader {
|
|
|
457
452
|
.resolve();
|
|
458
453
|
}
|
|
459
454
|
else {
|
|
460
|
-
return fetch(
|
|
455
|
+
return fetch(endpoint, {
|
|
461
456
|
method: 'POST',
|
|
462
457
|
credentials,
|
|
463
458
|
body: JSON.stringify(requestBody),
|
|
@@ -486,7 +481,15 @@ class UrlLoader {
|
|
|
486
481
|
else if (contentType === null || contentType === void 0 ? void 0 : contentType.includes('multipart/mixed')) {
|
|
487
482
|
return handleMultipartMixedResponse(fetchResult).then(resultStream => addCancelToResponseStream(resultStream, controller));
|
|
488
483
|
}
|
|
489
|
-
return fetchResult.
|
|
484
|
+
return fetchResult.text();
|
|
485
|
+
})
|
|
486
|
+
.then(result => {
|
|
487
|
+
if (typeof result === 'string') {
|
|
488
|
+
return JSON.parse(result);
|
|
489
|
+
}
|
|
490
|
+
else {
|
|
491
|
+
return result;
|
|
492
|
+
}
|
|
490
493
|
})
|
|
491
494
|
.resolve();
|
|
492
495
|
};
|
|
@@ -537,7 +540,7 @@ class UrlLoader {
|
|
|
537
540
|
connectionParams,
|
|
538
541
|
lazy: true,
|
|
539
542
|
});
|
|
540
|
-
return
|
|
543
|
+
return ({ document, variables, operationName, extensions }) => {
|
|
541
544
|
const query = print(document);
|
|
542
545
|
return observableToAsyncIterable({
|
|
543
546
|
subscribe: observer => {
|
|
@@ -563,7 +566,7 @@ class UrlLoader {
|
|
|
563
566
|
connectionParams,
|
|
564
567
|
lazy: true,
|
|
565
568
|
}, webSocketImpl);
|
|
566
|
-
return
|
|
569
|
+
return ({ document, variables, operationName }) => {
|
|
567
570
|
return observableToAsyncIterable(subscriptionClient.request({
|
|
568
571
|
query: document,
|
|
569
572
|
variables,
|
|
@@ -633,7 +636,7 @@ class UrlLoader {
|
|
|
633
636
|
return websocketImpl;
|
|
634
637
|
}
|
|
635
638
|
}
|
|
636
|
-
|
|
639
|
+
buildSubscriptionExecutor(subscriptionsEndpoint, fetch, importFn, options) {
|
|
637
640
|
if ((options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === SubscriptionProtocol.SSE) {
|
|
638
641
|
return this.buildHTTPExecutor(subscriptionsEndpoint, fetch, {
|
|
639
642
|
...options,
|
|
@@ -649,34 +652,47 @@ class UrlLoader {
|
|
|
649
652
|
return this.buildGraphQLSSEExecutor(subscriptionsEndpoint, fetch, options);
|
|
650
653
|
}
|
|
651
654
|
else {
|
|
652
|
-
const webSocketImpl =
|
|
655
|
+
const webSocketImpl$ = new ValueOrPromise(() => this.getWebSocketImpl(importFn, options));
|
|
653
656
|
const connectionParams = () => ({ headers: options === null || options === void 0 ? void 0 : options.headers });
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
657
|
+
const executor$ = webSocketImpl$.then(webSocketImpl => {
|
|
658
|
+
if ((options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === SubscriptionProtocol.LEGACY_WS) {
|
|
659
|
+
return this.buildWSLegacyExecutor(subscriptionsEndpoint, webSocketImpl, connectionParams);
|
|
660
|
+
}
|
|
661
|
+
else {
|
|
662
|
+
return this.buildWSExecutor(subscriptionsEndpoint, webSocketImpl, connectionParams);
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
return request => executor$.then(executor => executor(request)).resolve();
|
|
660
666
|
}
|
|
661
667
|
}
|
|
662
|
-
|
|
663
|
-
const fetch =
|
|
664
|
-
const httpExecutor =
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
+
getExecutor(endpoint, importFn, options) {
|
|
669
|
+
const fetch$ = new ValueOrPromise(() => this.getFetch(options === null || options === void 0 ? void 0 : options.customFetch, asyncImport));
|
|
670
|
+
const httpExecutor$ = fetch$.then(fetch => {
|
|
671
|
+
return this.buildHTTPExecutor(endpoint, fetch, options);
|
|
672
|
+
});
|
|
673
|
+
const subscriptionExecutor$ = fetch$.then(fetch => {
|
|
674
|
+
const subscriptionsEndpoint = (options === null || options === void 0 ? void 0 : options.subscriptionsEndpoint) || endpoint;
|
|
675
|
+
return this.buildSubscriptionExecutor(subscriptionsEndpoint, fetch, importFn, options);
|
|
676
|
+
});
|
|
677
|
+
function getExecutorByRequest(request) {
|
|
668
678
|
const operationAst = getOperationASTFromRequest(request);
|
|
669
679
|
if (operationAst.operation === 'subscription' ||
|
|
670
680
|
isLiveQueryOperationDefinitionNode(operationAst, request.variables)) {
|
|
671
|
-
return subscriptionExecutor
|
|
681
|
+
return subscriptionExecutor$;
|
|
672
682
|
}
|
|
673
|
-
|
|
674
|
-
|
|
683
|
+
else {
|
|
684
|
+
return httpExecutor$;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
return request => getExecutorByRequest(request)
|
|
688
|
+
.then(executor => executor(request))
|
|
689
|
+
.resolve();
|
|
690
|
+
}
|
|
691
|
+
getExecutorAsync(endpoint, options) {
|
|
692
|
+
return this.getExecutor(endpoint, asyncImport, options);
|
|
675
693
|
}
|
|
676
694
|
getExecutorSync(endpoint, options) {
|
|
677
|
-
|
|
678
|
-
const executor = this.buildHTTPExecutor(endpoint, fetch, options);
|
|
679
|
-
return executor;
|
|
695
|
+
return this.getExecutor(endpoint, syncImport, options);
|
|
680
696
|
}
|
|
681
697
|
handleSDL(pointer, fetch, options) {
|
|
682
698
|
const defaultMethod = this.getDefaultMethodFromOptions(options === null || options === void 0 ? void 0 : options.method, 'GET');
|
|
@@ -689,15 +705,15 @@ class UrlLoader {
|
|
|
689
705
|
.resolve();
|
|
690
706
|
}
|
|
691
707
|
async load(pointer, options) {
|
|
692
|
-
if (!(
|
|
708
|
+
if (!isCompatibleUri(pointer)) {
|
|
693
709
|
return [];
|
|
694
710
|
}
|
|
695
711
|
let source = {
|
|
696
712
|
location: pointer,
|
|
697
713
|
};
|
|
698
|
-
|
|
699
|
-
let executor = await this.getExecutorAsync(pointer, options);
|
|
714
|
+
let executor;
|
|
700
715
|
if ((options === null || options === void 0 ? void 0 : options.handleAsSDL) || pointer.endsWith('.graphql') || pointer.endsWith('.graphqls')) {
|
|
716
|
+
const fetch = await this.getFetch(options === null || options === void 0 ? void 0 : options.customFetch, asyncImport);
|
|
701
717
|
source = await this.handleSDL(pointer, fetch, options);
|
|
702
718
|
if (!source.schema && !source.document && !source.rawSDL) {
|
|
703
719
|
throw new Error(`Invalid SDL response`);
|
|
@@ -711,13 +727,14 @@ class UrlLoader {
|
|
|
711
727
|
: undefined);
|
|
712
728
|
}
|
|
713
729
|
else {
|
|
730
|
+
executor = this.getExecutorAsync(pointer, options);
|
|
714
731
|
source.schema = await introspectSchema(executor, {}, options);
|
|
715
732
|
}
|
|
716
733
|
if (!source.schema) {
|
|
717
734
|
throw new Error(`Invalid introspected schema`);
|
|
718
735
|
}
|
|
719
736
|
if (options === null || options === void 0 ? void 0 : options.endpoint) {
|
|
720
|
-
executor =
|
|
737
|
+
executor = this.getExecutorAsync(options.endpoint, options);
|
|
721
738
|
}
|
|
722
739
|
source.schema = wrapSchema({
|
|
723
740
|
schema: source.schema,
|
|
@@ -726,15 +743,15 @@ class UrlLoader {
|
|
|
726
743
|
return [source];
|
|
727
744
|
}
|
|
728
745
|
loadSync(pointer, options) {
|
|
729
|
-
if (!
|
|
746
|
+
if (!isCompatibleUri(pointer)) {
|
|
730
747
|
return [];
|
|
731
748
|
}
|
|
732
749
|
let source = {
|
|
733
750
|
location: pointer,
|
|
734
751
|
};
|
|
735
|
-
|
|
736
|
-
let executor = this.getExecutorSync(pointer, options);
|
|
752
|
+
let executor;
|
|
737
753
|
if ((options === null || options === void 0 ? void 0 : options.handleAsSDL) || pointer.endsWith('.graphql') || pointer.endsWith('.graphqls')) {
|
|
754
|
+
const fetch = this.getFetch(options === null || options === void 0 ? void 0 : options.customFetch, syncImport);
|
|
738
755
|
source = this.handleSDL(pointer, fetch, options);
|
|
739
756
|
if (!source.schema && !source.document && !source.rawSDL) {
|
|
740
757
|
throw new Error(`Invalid SDL response`);
|
|
@@ -748,6 +765,7 @@ class UrlLoader {
|
|
|
748
765
|
: undefined);
|
|
749
766
|
}
|
|
750
767
|
else {
|
|
768
|
+
executor = this.getExecutorSync(pointer, options);
|
|
751
769
|
source.schema = introspectSchema(executor, {}, options);
|
|
752
770
|
}
|
|
753
771
|
if (!source.schema) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/url-loader",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.9.2",
|
|
4
4
|
"description": "A set of utils for faster development of GraphQL tools",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@graphql-tools/delegate": "^8.5.1",
|
|
11
11
|
"@graphql-tools/utils": "^8.6.2",
|
|
12
|
-
"@graphql-tools/wrap": "^8.4.
|
|
12
|
+
"@graphql-tools/wrap": "^8.4.4",
|
|
13
13
|
"@n1ru4l/graphql-live-query": "^0.9.0",
|
|
14
14
|
"@types/websocket": "^1.0.4",
|
|
15
15
|
"@types/ws": "^8.0.0",
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
"subscriptions-transport-ws": "^0.11.0",
|
|
24
24
|
"sync-fetch": "^0.3.1",
|
|
25
25
|
"tslib": "^2.3.0",
|
|
26
|
-
"valid-url": "^1.0.9",
|
|
27
26
|
"value-or-promise": "^1.0.11",
|
|
28
27
|
"ws": "^8.3.0"
|
|
29
28
|
},
|