@graphql-tools/url-loader 8.0.26 → 8.0.28-alpha-20250225134153-2e7cd38b840ae22ac0382cd5c7c7b190ae4d4bb0

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 (3) hide show
  1. package/cjs/index.js +17 -13
  2. package/esm/index.js +18 -14
  3. package/package.json +4 -3
package/cjs/index.js CHANGED
@@ -9,6 +9,7 @@ const executor_http_1 = require("@graphql-tools/executor-http");
9
9
  const executor_legacy_ws_1 = require("@graphql-tools/executor-legacy-ws");
10
10
  const utils_1 = require("@graphql-tools/utils");
11
11
  const wrap_1 = require("@graphql-tools/wrap");
12
+ const promise_helpers_1 = require("@whatwg-node/promise-helpers");
12
13
  const defaultAsyncFetch_js_1 = require("./defaultAsyncFetch.js");
13
14
  const defaultSyncFetch_js_1 = require("./defaultSyncFetch.js");
14
15
  const asyncImport = (moduleName) => Promise.resolve(`${`${moduleName}`}`).then(s => tslib_1.__importStar(require(s)));
@@ -84,7 +85,7 @@ class UrlLoader {
84
85
  if (customFetch) {
85
86
  if (typeof customFetch === 'string') {
86
87
  const [moduleName, fetchFnName] = customFetch.split('#');
87
- return (0, utils_1.mapMaybePromise)(importFn(moduleName), module => fetchFnName ? module[fetchFnName] : module);
88
+ return (0, promise_helpers_1.handleMaybePromise)(() => importFn(moduleName), module => (fetchFnName ? module[fetchFnName] : module));
88
89
  }
89
90
  else if (typeof customFetch === 'function') {
90
91
  return customFetch;
@@ -106,7 +107,7 @@ class UrlLoader {
106
107
  getWebSocketImpl(importFn, options) {
107
108
  if (typeof options?.webSocketImpl === 'string') {
108
109
  const [moduleName, webSocketImplName] = options.webSocketImpl.split('#');
109
- return (0, utils_1.mapMaybePromise)(importFn(moduleName), importedModule => webSocketImplName ? importedModule[webSocketImplName] : importedModule);
110
+ return (0, promise_helpers_1.handleMaybePromise)(() => importFn(moduleName), importedModule => (webSocketImplName ? importedModule[webSocketImplName] : importedModule));
110
111
  }
111
112
  else {
112
113
  const websocketImpl = options?.webSocketImpl || isomorphic_ws_1.default;
@@ -126,23 +127,26 @@ class UrlLoader {
126
127
  return this.buildHTTPExecutor(subscriptionsEndpoint, fetch, options);
127
128
  }
128
129
  else {
129
- const executor$ = (0, utils_1.mapMaybePromise)(this.getWebSocketImpl(importFn, options), webSocketImpl => {
130
+ return request => (0, promise_helpers_1.handleMaybePromise)(() => (0, promise_helpers_1.handleMaybePromise)(() => this.getWebSocketImpl(importFn, options), webSocketImpl => {
130
131
  if (options?.subscriptionsProtocol === SubscriptionProtocol.LEGACY_WS) {
131
132
  return this.buildWSLegacyExecutor(subscriptionsEndpoint, webSocketImpl, options);
132
133
  }
133
134
  else {
134
135
  return this.buildWSExecutor(subscriptionsEndpoint, webSocketImpl, options?.connectionParams);
135
136
  }
136
- });
137
- return request => (0, utils_1.mapMaybePromise)(executor$, executor => executor(request));
137
+ }), executor => executor(request));
138
138
  }
139
139
  }
140
140
  getExecutor(endpoint, importFn, options) {
141
- const fetch$ = this.getFetch(options?.customFetch, importFn);
142
- const httpExecutor$ = (0, utils_1.mapMaybePromise)(fetch$, fetch => this.buildHTTPExecutor(endpoint, fetch, options));
141
+ let fetch$;
142
+ const getHttpExecutor = () => {
143
+ return (0, promise_helpers_1.handleMaybePromise)(() => (fetch$ ||= this.getFetch(options?.customFetch, importFn)), fetch => this.buildHTTPExecutor(endpoint, fetch, options));
144
+ };
145
+ const getSetHttpExecutor$ = () => (httpExecutor$ ||= getHttpExecutor());
146
+ let httpExecutor$;
143
147
  if (options?.subscriptionsEndpoint != null ||
144
148
  options?.subscriptionsProtocol !== SubscriptionProtocol.SSE) {
145
- const subscriptionExecutor$ = (0, utils_1.mapMaybePromise)(fetch$, fetch => {
149
+ const subscriptionExecutor$ = (0, promise_helpers_1.handleMaybePromise)(() => (fetch$ ||= this.getFetch(options?.customFetch, importFn)), fetch => {
146
150
  const subscriptionsEndpoint = options?.subscriptionsEndpoint || endpoint;
147
151
  return this.buildSubscriptionExecutor(subscriptionsEndpoint, fetch, importFn, options);
148
152
  });
@@ -157,13 +161,13 @@ class UrlLoader {
157
161
  return subscriptionExecutor$;
158
162
  }
159
163
  else {
160
- return httpExecutor$;
164
+ return getSetHttpExecutor$();
161
165
  }
162
166
  }
163
- return request => (0, utils_1.mapMaybePromise)(getExecutorByRequest(request), executor => executor(request));
167
+ return request => (0, promise_helpers_1.handleMaybePromise)(() => getExecutorByRequest(request), executor => executor(request));
164
168
  }
165
169
  else {
166
- return request => (0, utils_1.mapMaybePromise)(httpExecutor$, executor => executor(request));
170
+ return request => (0, promise_helpers_1.handleMaybePromise)(getSetHttpExecutor$, executor => executor(request));
167
171
  }
168
172
  }
169
173
  getExecutorAsync(endpoint, options) {
@@ -174,10 +178,10 @@ class UrlLoader {
174
178
  }
175
179
  handleSDL(pointer, fetch, options) {
176
180
  const defaultMethod = this.getDefaultMethodFromOptions(options?.method, 'GET');
177
- return (0, utils_1.mapMaybePromise)(fetch(pointer, {
181
+ return (0, promise_helpers_1.handleMaybePromise)(() => fetch(pointer, {
178
182
  method: defaultMethod,
179
183
  headers: typeof options?.headers === 'function' ? options.headers() : options?.headers,
180
- }), res => (0, utils_1.mapMaybePromise)(res.text(), schemaString => (0, utils_1.parseGraphQLSDL)(pointer, schemaString, options)));
184
+ }), res => (0, promise_helpers_1.handleMaybePromise)(() => res.text(), schemaString => (0, utils_1.parseGraphQLSDL)(pointer, schemaString, options)));
181
185
  }
182
186
  async load(pointer, options) {
183
187
  if (!isCompatibleUri(pointer)) {
package/esm/index.js CHANGED
@@ -3,8 +3,9 @@ import WebSocket from 'isomorphic-ws';
3
3
  import { buildGraphQLWSExecutor } from '@graphql-tools/executor-graphql-ws';
4
4
  import { buildHTTPExecutor, isLiveQueryOperationDefinitionNode, } from '@graphql-tools/executor-http';
5
5
  import { buildWSLegacyExecutor } from '@graphql-tools/executor-legacy-ws';
6
- import { getOperationASTFromRequest, isUrl, mapMaybePromise, parseGraphQLSDL, } from '@graphql-tools/utils';
6
+ import { getOperationASTFromRequest, isUrl, parseGraphQLSDL, } from '@graphql-tools/utils';
7
7
  import { schemaFromExecutor, wrapSchema } from '@graphql-tools/wrap';
8
+ import { handleMaybePromise } from '@whatwg-node/promise-helpers';
8
9
  import { defaultAsyncFetch } from './defaultAsyncFetch.js';
9
10
  import { defaultSyncFetch } from './defaultSyncFetch.js';
10
11
  const asyncImport = (moduleName) => import(`${moduleName}`);
@@ -80,7 +81,7 @@ export class UrlLoader {
80
81
  if (customFetch) {
81
82
  if (typeof customFetch === 'string') {
82
83
  const [moduleName, fetchFnName] = customFetch.split('#');
83
- return mapMaybePromise(importFn(moduleName), module => fetchFnName ? module[fetchFnName] : module);
84
+ return handleMaybePromise(() => importFn(moduleName), module => (fetchFnName ? module[fetchFnName] : module));
84
85
  }
85
86
  else if (typeof customFetch === 'function') {
86
87
  return customFetch;
@@ -102,7 +103,7 @@ export class UrlLoader {
102
103
  getWebSocketImpl(importFn, options) {
103
104
  if (typeof options?.webSocketImpl === 'string') {
104
105
  const [moduleName, webSocketImplName] = options.webSocketImpl.split('#');
105
- return mapMaybePromise(importFn(moduleName), importedModule => webSocketImplName ? importedModule[webSocketImplName] : importedModule);
106
+ return handleMaybePromise(() => importFn(moduleName), importedModule => (webSocketImplName ? importedModule[webSocketImplName] : importedModule));
106
107
  }
107
108
  else {
108
109
  const websocketImpl = options?.webSocketImpl || WebSocket;
@@ -122,23 +123,26 @@ export class UrlLoader {
122
123
  return this.buildHTTPExecutor(subscriptionsEndpoint, fetch, options);
123
124
  }
124
125
  else {
125
- const executor$ = mapMaybePromise(this.getWebSocketImpl(importFn, options), webSocketImpl => {
126
+ return request => handleMaybePromise(() => handleMaybePromise(() => this.getWebSocketImpl(importFn, options), webSocketImpl => {
126
127
  if (options?.subscriptionsProtocol === SubscriptionProtocol.LEGACY_WS) {
127
128
  return this.buildWSLegacyExecutor(subscriptionsEndpoint, webSocketImpl, options);
128
129
  }
129
130
  else {
130
131
  return this.buildWSExecutor(subscriptionsEndpoint, webSocketImpl, options?.connectionParams);
131
132
  }
132
- });
133
- return request => mapMaybePromise(executor$, executor => executor(request));
133
+ }), executor => executor(request));
134
134
  }
135
135
  }
136
136
  getExecutor(endpoint, importFn, options) {
137
- const fetch$ = this.getFetch(options?.customFetch, importFn);
138
- const httpExecutor$ = mapMaybePromise(fetch$, fetch => this.buildHTTPExecutor(endpoint, fetch, options));
137
+ let fetch$;
138
+ const getHttpExecutor = () => {
139
+ return handleMaybePromise(() => (fetch$ ||= this.getFetch(options?.customFetch, importFn)), fetch => this.buildHTTPExecutor(endpoint, fetch, options));
140
+ };
141
+ const getSetHttpExecutor$ = () => (httpExecutor$ ||= getHttpExecutor());
142
+ let httpExecutor$;
139
143
  if (options?.subscriptionsEndpoint != null ||
140
144
  options?.subscriptionsProtocol !== SubscriptionProtocol.SSE) {
141
- const subscriptionExecutor$ = mapMaybePromise(fetch$, fetch => {
145
+ const subscriptionExecutor$ = handleMaybePromise(() => (fetch$ ||= this.getFetch(options?.customFetch, importFn)), fetch => {
142
146
  const subscriptionsEndpoint = options?.subscriptionsEndpoint || endpoint;
143
147
  return this.buildSubscriptionExecutor(subscriptionsEndpoint, fetch, importFn, options);
144
148
  });
@@ -153,13 +157,13 @@ export class UrlLoader {
153
157
  return subscriptionExecutor$;
154
158
  }
155
159
  else {
156
- return httpExecutor$;
160
+ return getSetHttpExecutor$();
157
161
  }
158
162
  }
159
- return request => mapMaybePromise(getExecutorByRequest(request), executor => executor(request));
163
+ return request => handleMaybePromise(() => getExecutorByRequest(request), executor => executor(request));
160
164
  }
161
165
  else {
162
- return request => mapMaybePromise(httpExecutor$, executor => executor(request));
166
+ return request => handleMaybePromise(getSetHttpExecutor$, executor => executor(request));
163
167
  }
164
168
  }
165
169
  getExecutorAsync(endpoint, options) {
@@ -170,10 +174,10 @@ export class UrlLoader {
170
174
  }
171
175
  handleSDL(pointer, fetch, options) {
172
176
  const defaultMethod = this.getDefaultMethodFromOptions(options?.method, 'GET');
173
- return mapMaybePromise(fetch(pointer, {
177
+ return handleMaybePromise(() => fetch(pointer, {
174
178
  method: defaultMethod,
175
179
  headers: typeof options?.headers === 'function' ? options.headers() : options?.headers,
176
- }), res => mapMaybePromise(res.text(), schemaString => parseGraphQLSDL(pointer, schemaString, options)));
180
+ }), res => handleMaybePromise(() => res.text(), schemaString => parseGraphQLSDL(pointer, schemaString, options)));
177
181
  }
178
182
  async load(pointer, options) {
179
183
  if (!isCompatibleUri(pointer)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/url-loader",
3
- "version": "8.0.26",
3
+ "version": "8.0.28-alpha-20250225134153-2e7cd38b840ae22ac0382cd5c7c7b190ae4d4bb0",
4
4
  "description": "A set of utils for faster development of GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -9,11 +9,12 @@
9
9
  "dependencies": {
10
10
  "@graphql-tools/executor-graphql-ws": "^2.0.1",
11
11
  "@graphql-tools/executor-http": "^1.1.9",
12
- "@graphql-tools/executor-legacy-ws": "^1.1.12",
13
- "@graphql-tools/utils": "^10.8.1",
12
+ "@graphql-tools/executor-legacy-ws": "1.1.14-alpha-20250225134153-2e7cd38b840ae22ac0382cd5c7c7b190ae4d4bb0",
13
+ "@graphql-tools/utils": "10.8.3-alpha-20250225134153-2e7cd38b840ae22ac0382cd5c7c7b190ae4d4bb0",
14
14
  "@graphql-tools/wrap": "^10.0.16",
15
15
  "@types/ws": "^8.0.0",
16
16
  "@whatwg-node/fetch": "^0.10.0",
17
+ "@whatwg-node/promise-helpers": "^1.0.0",
17
18
  "isomorphic-ws": "^5.0.0",
18
19
  "sync-fetch": "0.6.0-2",
19
20
  "tslib": "^2.4.0",