@graphql-tools/url-loader 7.9.0 → 7.9.1
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 +52 -42
- package/index.mjs +53 -43
- package/package.json +1 -2
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) ||
|
|
@@ -569,7 +564,7 @@ class UrlLoader {
|
|
|
569
564
|
connectionParams,
|
|
570
565
|
lazy: true,
|
|
571
566
|
});
|
|
572
|
-
return
|
|
567
|
+
return ({ document, variables, operationName, extensions }) => {
|
|
573
568
|
const query = graphql.print(document);
|
|
574
569
|
return utils.observableToAsyncIterable({
|
|
575
570
|
subscribe: observer => {
|
|
@@ -595,7 +590,7 @@ class UrlLoader {
|
|
|
595
590
|
connectionParams,
|
|
596
591
|
lazy: true,
|
|
597
592
|
}, webSocketImpl);
|
|
598
|
-
return
|
|
593
|
+
return ({ document, variables, operationName }) => {
|
|
599
594
|
return utils.observableToAsyncIterable(subscriptionClient.request({
|
|
600
595
|
query: document,
|
|
601
596
|
variables,
|
|
@@ -665,7 +660,7 @@ class UrlLoader {
|
|
|
665
660
|
return websocketImpl;
|
|
666
661
|
}
|
|
667
662
|
}
|
|
668
|
-
|
|
663
|
+
buildSubscriptionExecutor(subscriptionsEndpoint, fetch, importFn, options) {
|
|
669
664
|
if ((options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === exports.SubscriptionProtocol.SSE) {
|
|
670
665
|
return this.buildHTTPExecutor(subscriptionsEndpoint, fetch, {
|
|
671
666
|
...options,
|
|
@@ -681,34 +676,47 @@ class UrlLoader {
|
|
|
681
676
|
return this.buildGraphQLSSEExecutor(subscriptionsEndpoint, fetch, options);
|
|
682
677
|
}
|
|
683
678
|
else {
|
|
684
|
-
const webSocketImpl =
|
|
679
|
+
const webSocketImpl$ = new valueOrPromise.ValueOrPromise(() => this.getWebSocketImpl(importFn, options));
|
|
685
680
|
const connectionParams = () => ({ headers: options === null || options === void 0 ? void 0 : options.headers });
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
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();
|
|
692
690
|
}
|
|
693
691
|
}
|
|
694
|
-
|
|
695
|
-
const fetch =
|
|
696
|
-
const httpExecutor =
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
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) {
|
|
700
702
|
const operationAst = utils.getOperationASTFromRequest(request);
|
|
701
703
|
if (operationAst.operation === 'subscription' ||
|
|
702
704
|
graphqlLiveQuery.isLiveQueryOperationDefinitionNode(operationAst, request.variables)) {
|
|
703
|
-
return subscriptionExecutor
|
|
705
|
+
return subscriptionExecutor$;
|
|
704
706
|
}
|
|
705
|
-
|
|
706
|
-
|
|
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);
|
|
707
717
|
}
|
|
708
718
|
getExecutorSync(endpoint, options) {
|
|
709
|
-
|
|
710
|
-
const executor = this.buildHTTPExecutor(endpoint, fetch, options);
|
|
711
|
-
return executor;
|
|
719
|
+
return this.getExecutor(endpoint, syncImport, options);
|
|
712
720
|
}
|
|
713
721
|
handleSDL(pointer, fetch, options) {
|
|
714
722
|
const defaultMethod = this.getDefaultMethodFromOptions(options === null || options === void 0 ? void 0 : options.method, 'GET');
|
|
@@ -721,15 +729,15 @@ class UrlLoader {
|
|
|
721
729
|
.resolve();
|
|
722
730
|
}
|
|
723
731
|
async load(pointer, options) {
|
|
724
|
-
if (!(
|
|
732
|
+
if (!isCompatibleUri(pointer)) {
|
|
725
733
|
return [];
|
|
726
734
|
}
|
|
727
735
|
let source = {
|
|
728
736
|
location: pointer,
|
|
729
737
|
};
|
|
730
|
-
|
|
731
|
-
let executor = await this.getExecutorAsync(pointer, options);
|
|
738
|
+
let executor;
|
|
732
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);
|
|
733
741
|
source = await this.handleSDL(pointer, fetch, options);
|
|
734
742
|
if (!source.schema && !source.document && !source.rawSDL) {
|
|
735
743
|
throw new Error(`Invalid SDL response`);
|
|
@@ -743,13 +751,14 @@ class UrlLoader {
|
|
|
743
751
|
: undefined);
|
|
744
752
|
}
|
|
745
753
|
else {
|
|
754
|
+
executor = this.getExecutorAsync(pointer, options);
|
|
746
755
|
source.schema = await wrap.introspectSchema(executor, {}, options);
|
|
747
756
|
}
|
|
748
757
|
if (!source.schema) {
|
|
749
758
|
throw new Error(`Invalid introspected schema`);
|
|
750
759
|
}
|
|
751
760
|
if (options === null || options === void 0 ? void 0 : options.endpoint) {
|
|
752
|
-
executor =
|
|
761
|
+
executor = this.getExecutorAsync(options.endpoint, options);
|
|
753
762
|
}
|
|
754
763
|
source.schema = wrap.wrapSchema({
|
|
755
764
|
schema: source.schema,
|
|
@@ -758,15 +767,15 @@ class UrlLoader {
|
|
|
758
767
|
return [source];
|
|
759
768
|
}
|
|
760
769
|
loadSync(pointer, options) {
|
|
761
|
-
if (!
|
|
770
|
+
if (!isCompatibleUri(pointer)) {
|
|
762
771
|
return [];
|
|
763
772
|
}
|
|
764
773
|
let source = {
|
|
765
774
|
location: pointer,
|
|
766
775
|
};
|
|
767
|
-
|
|
768
|
-
let executor = this.getExecutorSync(pointer, options);
|
|
776
|
+
let executor;
|
|
769
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);
|
|
770
779
|
source = this.handleSDL(pointer, fetch, options);
|
|
771
780
|
if (!source.schema && !source.document && !source.rawSDL) {
|
|
772
781
|
throw new Error(`Invalid SDL response`);
|
|
@@ -780,6 +789,7 @@ class UrlLoader {
|
|
|
780
789
|
: undefined);
|
|
781
790
|
}
|
|
782
791
|
else {
|
|
792
|
+
executor = this.getExecutorSync(pointer, options);
|
|
783
793
|
source.schema = wrap.introspectSchema(executor, {}, options);
|
|
784
794
|
}
|
|
785
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) ||
|
|
@@ -545,7 +540,7 @@ class UrlLoader {
|
|
|
545
540
|
connectionParams,
|
|
546
541
|
lazy: true,
|
|
547
542
|
});
|
|
548
|
-
return
|
|
543
|
+
return ({ document, variables, operationName, extensions }) => {
|
|
549
544
|
const query = print(document);
|
|
550
545
|
return observableToAsyncIterable({
|
|
551
546
|
subscribe: observer => {
|
|
@@ -571,7 +566,7 @@ class UrlLoader {
|
|
|
571
566
|
connectionParams,
|
|
572
567
|
lazy: true,
|
|
573
568
|
}, webSocketImpl);
|
|
574
|
-
return
|
|
569
|
+
return ({ document, variables, operationName }) => {
|
|
575
570
|
return observableToAsyncIterable(subscriptionClient.request({
|
|
576
571
|
query: document,
|
|
577
572
|
variables,
|
|
@@ -641,7 +636,7 @@ class UrlLoader {
|
|
|
641
636
|
return websocketImpl;
|
|
642
637
|
}
|
|
643
638
|
}
|
|
644
|
-
|
|
639
|
+
buildSubscriptionExecutor(subscriptionsEndpoint, fetch, importFn, options) {
|
|
645
640
|
if ((options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === SubscriptionProtocol.SSE) {
|
|
646
641
|
return this.buildHTTPExecutor(subscriptionsEndpoint, fetch, {
|
|
647
642
|
...options,
|
|
@@ -657,34 +652,47 @@ class UrlLoader {
|
|
|
657
652
|
return this.buildGraphQLSSEExecutor(subscriptionsEndpoint, fetch, options);
|
|
658
653
|
}
|
|
659
654
|
else {
|
|
660
|
-
const webSocketImpl =
|
|
655
|
+
const webSocketImpl$ = new ValueOrPromise(() => this.getWebSocketImpl(importFn, options));
|
|
661
656
|
const connectionParams = () => ({ headers: options === null || options === void 0 ? void 0 : options.headers });
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
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();
|
|
668
666
|
}
|
|
669
667
|
}
|
|
670
|
-
|
|
671
|
-
const fetch =
|
|
672
|
-
const httpExecutor =
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
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) {
|
|
676
678
|
const operationAst = getOperationASTFromRequest(request);
|
|
677
679
|
if (operationAst.operation === 'subscription' ||
|
|
678
680
|
isLiveQueryOperationDefinitionNode(operationAst, request.variables)) {
|
|
679
|
-
return subscriptionExecutor
|
|
681
|
+
return subscriptionExecutor$;
|
|
680
682
|
}
|
|
681
|
-
|
|
682
|
-
|
|
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);
|
|
683
693
|
}
|
|
684
694
|
getExecutorSync(endpoint, options) {
|
|
685
|
-
|
|
686
|
-
const executor = this.buildHTTPExecutor(endpoint, fetch, options);
|
|
687
|
-
return executor;
|
|
695
|
+
return this.getExecutor(endpoint, syncImport, options);
|
|
688
696
|
}
|
|
689
697
|
handleSDL(pointer, fetch, options) {
|
|
690
698
|
const defaultMethod = this.getDefaultMethodFromOptions(options === null || options === void 0 ? void 0 : options.method, 'GET');
|
|
@@ -697,15 +705,15 @@ class UrlLoader {
|
|
|
697
705
|
.resolve();
|
|
698
706
|
}
|
|
699
707
|
async load(pointer, options) {
|
|
700
|
-
if (!(
|
|
708
|
+
if (!isCompatibleUri(pointer)) {
|
|
701
709
|
return [];
|
|
702
710
|
}
|
|
703
711
|
let source = {
|
|
704
712
|
location: pointer,
|
|
705
713
|
};
|
|
706
|
-
|
|
707
|
-
let executor = await this.getExecutorAsync(pointer, options);
|
|
714
|
+
let executor;
|
|
708
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);
|
|
709
717
|
source = await this.handleSDL(pointer, fetch, options);
|
|
710
718
|
if (!source.schema && !source.document && !source.rawSDL) {
|
|
711
719
|
throw new Error(`Invalid SDL response`);
|
|
@@ -719,13 +727,14 @@ class UrlLoader {
|
|
|
719
727
|
: undefined);
|
|
720
728
|
}
|
|
721
729
|
else {
|
|
730
|
+
executor = this.getExecutorAsync(pointer, options);
|
|
722
731
|
source.schema = await introspectSchema(executor, {}, options);
|
|
723
732
|
}
|
|
724
733
|
if (!source.schema) {
|
|
725
734
|
throw new Error(`Invalid introspected schema`);
|
|
726
735
|
}
|
|
727
736
|
if (options === null || options === void 0 ? void 0 : options.endpoint) {
|
|
728
|
-
executor =
|
|
737
|
+
executor = this.getExecutorAsync(options.endpoint, options);
|
|
729
738
|
}
|
|
730
739
|
source.schema = wrapSchema({
|
|
731
740
|
schema: source.schema,
|
|
@@ -734,15 +743,15 @@ class UrlLoader {
|
|
|
734
743
|
return [source];
|
|
735
744
|
}
|
|
736
745
|
loadSync(pointer, options) {
|
|
737
|
-
if (!
|
|
746
|
+
if (!isCompatibleUri(pointer)) {
|
|
738
747
|
return [];
|
|
739
748
|
}
|
|
740
749
|
let source = {
|
|
741
750
|
location: pointer,
|
|
742
751
|
};
|
|
743
|
-
|
|
744
|
-
let executor = this.getExecutorSync(pointer, options);
|
|
752
|
+
let executor;
|
|
745
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);
|
|
746
755
|
source = this.handleSDL(pointer, fetch, options);
|
|
747
756
|
if (!source.schema && !source.document && !source.rawSDL) {
|
|
748
757
|
throw new Error(`Invalid SDL response`);
|
|
@@ -756,6 +765,7 @@ class UrlLoader {
|
|
|
756
765
|
: undefined);
|
|
757
766
|
}
|
|
758
767
|
else {
|
|
768
|
+
executor = this.getExecutorSync(pointer, options);
|
|
759
769
|
source.schema = introspectSchema(executor, {}, options);
|
|
760
770
|
}
|
|
761
771
|
if (!source.schema) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/url-loader",
|
|
3
|
-
"version": "7.9.
|
|
3
|
+
"version": "7.9.1",
|
|
4
4
|
"description": "A set of utils for faster development of GraphQL tools",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
@@ -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
|
},
|