@graphql-tools/url-loader 7.8.0-alpha-4faabc4b.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.
Files changed (4) hide show
  1. package/index.d.ts +9 -8
  2. package/index.js +62 -44
  3. package/index.mjs +63 -45
  4. 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']): AsyncExecutor;
128
- buildWSLegacyExecutor(subscriptionsEndpoint: string, webSocketImpl: typeof WebSocket, connectionParams?: ConnectionParamsOptions): AsyncExecutor;
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: AsyncFetchFn, options?: LoadFromUrlOptions): Promise<AsyncExecutor>;
136
- getExecutorAsync(endpoint: string, options?: Omit<LoadFromUrlOptions, 'endpoint'>): Promise<AsyncExecutor>;
137
- getExecutorSync(endpoint: string, options: Omit<LoadFromUrlOptions, 'endpoint'>): SyncExecutor;
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
- const isCompatibleUri = (uri) => {
300
- if (validUrl.isWebUri(uri)) {
298
+ function isCompatibleUri(uri) {
299
+ try {
300
+ // eslint-disable-next-line no-new
301
+ new URL(uri);
301
302
  return true;
302
303
  }
303
- // we just replace the url part, the remaining validation is the same
304
- const wsUri = uri.replace('wss://', 'http://').replace('ws://', 'http://');
305
- return !!validUrl.isWebUri(wsUri);
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) ||
@@ -448,7 +443,7 @@ class UrlLoader {
448
443
  }
449
444
  }, options.timeout);
450
445
  }
451
- const credentials = (options === null || options === void 0 ? void 0 : options.credentials) || 'include';
446
+ const credentials = (options === null || options === void 0 ? void 0 : options.credentials) || 'same-origin';
452
447
  return new valueOrPromise.ValueOrPromise(() => {
453
448
  switch (method) {
454
449
  case 'GET':
@@ -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.json();
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 async ({ document, variables, operationName, extensions }) => {
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 async ({ document, variables, operationName }) => {
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
- async buildSubscriptionExecutor(subscriptionsEndpoint, fetch, options) {
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 = await this.getWebSocketImpl(asyncImport, options);
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
- if ((options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === exports.SubscriptionProtocol.LEGACY_WS) {
679
- return this.buildWSLegacyExecutor(subscriptionsEndpoint, webSocketImpl, connectionParams);
680
- }
681
- else {
682
- return this.buildWSExecutor(subscriptionsEndpoint, webSocketImpl, connectionParams);
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
- async getExecutorAsync(endpoint, options) {
687
- const fetch = await this.getFetch(options === null || options === void 0 ? void 0 : options.customFetch, asyncImport);
688
- const httpExecutor = this.buildHTTPExecutor(endpoint, fetch, options);
689
- const subscriptionsEndpoint = (options === null || options === void 0 ? void 0 : options.subscriptionsEndpoint) || endpoint;
690
- const subscriptionExecutor = await this.buildSubscriptionExecutor(subscriptionsEndpoint, fetch, options);
691
- return request => {
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(request);
705
+ return subscriptionExecutor$;
696
706
  }
697
- return httpExecutor(request);
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
- const fetch = this.getFetch(options === null || options === void 0 ? void 0 : options.customFetch, syncImport);
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 (!(await this.canLoad(pointer, options))) {
732
+ if (!isCompatibleUri(pointer)) {
717
733
  return [];
718
734
  }
719
735
  let source = {
720
736
  location: pointer,
721
737
  };
722
- const fetch = await this.getFetch(options === null || options === void 0 ? void 0 : options.customFetch, asyncImport);
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 = await this.getExecutorAsync(options.endpoint, options);
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 (!this.canLoadSync(pointer, options)) {
770
+ if (!isCompatibleUri(pointer)) {
754
771
  return [];
755
772
  }
756
773
  let source = {
757
774
  location: pointer,
758
775
  };
759
- const fetch = this.getFetch(options === null || options === void 0 ? void 0 : options.customFetch, syncImport);
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, getOperationASTFromRequest, parseGraphQLSDL } from '@graphql-tools/utils';
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
- const isCompatibleUri = (uri) => {
276
- if (isWebUri(uri)) {
274
+ function isCompatibleUri(uri) {
275
+ try {
276
+ // eslint-disable-next-line no-new
277
+ new URL(uri);
277
278
  return true;
278
279
  }
279
- // we just replace the url part, the remaining validation is the same
280
- const wsUri = uri.replace('wss://', 'http://').replace('ws://', 'http://');
281
- return !!isWebUri(wsUri);
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) ||
@@ -424,7 +419,7 @@ class UrlLoader {
424
419
  }
425
420
  }, options.timeout);
426
421
  }
427
- const credentials = (options === null || options === void 0 ? void 0 : options.credentials) || 'include';
422
+ const credentials = (options === null || options === void 0 ? void 0 : options.credentials) || 'same-origin';
428
423
  return new ValueOrPromise(() => {
429
424
  switch (method) {
430
425
  case 'GET':
@@ -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.json();
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 async ({ document, variables, operationName, extensions }) => {
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 async ({ document, variables, operationName }) => {
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
- async buildSubscriptionExecutor(subscriptionsEndpoint, fetch, options) {
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 = await this.getWebSocketImpl(asyncImport, options);
655
+ const webSocketImpl$ = new ValueOrPromise(() => this.getWebSocketImpl(importFn, options));
653
656
  const connectionParams = () => ({ headers: options === null || options === void 0 ? void 0 : options.headers });
654
- if ((options === null || options === void 0 ? void 0 : options.subscriptionsProtocol) === SubscriptionProtocol.LEGACY_WS) {
655
- return this.buildWSLegacyExecutor(subscriptionsEndpoint, webSocketImpl, connectionParams);
656
- }
657
- else {
658
- return this.buildWSExecutor(subscriptionsEndpoint, webSocketImpl, connectionParams);
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
- async getExecutorAsync(endpoint, options) {
663
- const fetch = await this.getFetch(options === null || options === void 0 ? void 0 : options.customFetch, asyncImport);
664
- const httpExecutor = this.buildHTTPExecutor(endpoint, fetch, options);
665
- const subscriptionsEndpoint = (options === null || options === void 0 ? void 0 : options.subscriptionsEndpoint) || endpoint;
666
- const subscriptionExecutor = await this.buildSubscriptionExecutor(subscriptionsEndpoint, fetch, options);
667
- return request => {
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(request);
681
+ return subscriptionExecutor$;
672
682
  }
673
- return httpExecutor(request);
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
- const fetch = this.getFetch(options === null || options === void 0 ? void 0 : options.customFetch, syncImport);
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 (!(await this.canLoad(pointer, options))) {
708
+ if (!isCompatibleUri(pointer)) {
693
709
  return [];
694
710
  }
695
711
  let source = {
696
712
  location: pointer,
697
713
  };
698
- const fetch = await this.getFetch(options === null || options === void 0 ? void 0 : options.customFetch, asyncImport);
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 = await this.getExecutorAsync(options.endpoint, options);
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 (!this.canLoadSync(pointer, options)) {
746
+ if (!isCompatibleUri(pointer)) {
730
747
  return [];
731
748
  }
732
749
  let source = {
733
750
  location: pointer,
734
751
  };
735
- const fetch = this.getFetch(options === null || options === void 0 ? void 0 : options.customFetch, syncImport);
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.8.0-alpha-4faabc4b.0",
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
  },