@graphql-tools/url-loader 8.0.25-alpha-20250130084102-0293c7e33db7171829b11520fa3c5062fb44cb3d → 8.0.25-alpha-20250209212603-8422ca208e29154daa75f23ffdc70e969464572b
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/cjs/defaultAsyncFetch.js +1 -4
- package/cjs/index.js +14 -30
- package/esm/defaultAsyncFetch.js +1 -3
- package/esm/index.js +15 -31
- package/package.json +3 -4
package/cjs/defaultAsyncFetch.js
CHANGED
|
@@ -2,7 +2,4 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defaultAsyncFetch = void 0;
|
|
4
4
|
const fetch_1 = require("@whatwg-node/fetch");
|
|
5
|
-
|
|
6
|
-
return (0, fetch_1.fetch)(input, init);
|
|
7
|
-
};
|
|
8
|
-
exports.defaultAsyncFetch = defaultAsyncFetch;
|
|
5
|
+
exports.defaultAsyncFetch = fetch_1.fetch;
|
package/cjs/index.js
CHANGED
|
@@ -4,7 +4,6 @@ exports.UrlLoader = exports.SubscriptionProtocol = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const graphql_1 = require("graphql");
|
|
6
6
|
const isomorphic_ws_1 = tslib_1.__importDefault(require("isomorphic-ws"));
|
|
7
|
-
const value_or_promise_1 = require("value-or-promise");
|
|
8
7
|
const executor_graphql_ws_1 = require("@graphql-tools/executor-graphql-ws");
|
|
9
8
|
const executor_http_1 = require("@graphql-tools/executor-http");
|
|
10
9
|
const executor_legacy_ws_1 = require("@graphql-tools/executor-legacy-ws");
|
|
@@ -33,13 +32,10 @@ var SubscriptionProtocol;
|
|
|
33
32
|
})(SubscriptionProtocol || (exports.SubscriptionProtocol = SubscriptionProtocol = {}));
|
|
34
33
|
const acceptableProtocols = ['http:', 'https:', 'ws:', 'wss:'];
|
|
35
34
|
function isCompatibleUri(uri) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return acceptableProtocols.includes(url.protocol);
|
|
39
|
-
}
|
|
40
|
-
catch {
|
|
41
|
-
return false;
|
|
35
|
+
if (acceptableProtocols.some(protocol => uri.startsWith(protocol))) {
|
|
36
|
+
return (0, utils_1.isUrl)(uri);
|
|
42
37
|
}
|
|
38
|
+
return false;
|
|
43
39
|
}
|
|
44
40
|
/**
|
|
45
41
|
* This loader loads a schema from a URL. The loaded schema is a fully-executable,
|
|
@@ -87,9 +83,7 @@ class UrlLoader {
|
|
|
87
83
|
if (customFetch) {
|
|
88
84
|
if (typeof customFetch === 'string') {
|
|
89
85
|
const [moduleName, fetchFnName] = customFetch.split('#');
|
|
90
|
-
return
|
|
91
|
-
.then(module => (fetchFnName ? module[fetchFnName] : module))
|
|
92
|
-
.resolve();
|
|
86
|
+
return (0, utils_1.mapMaybePromise)(importFn(moduleName), module => fetchFnName ? module[fetchFnName] : module);
|
|
93
87
|
}
|
|
94
88
|
else if (typeof customFetch === 'function') {
|
|
95
89
|
return customFetch;
|
|
@@ -111,9 +105,7 @@ class UrlLoader {
|
|
|
111
105
|
getWebSocketImpl(importFn, options) {
|
|
112
106
|
if (typeof options?.webSocketImpl === 'string') {
|
|
113
107
|
const [moduleName, webSocketImplName] = options.webSocketImpl.split('#');
|
|
114
|
-
return
|
|
115
|
-
.then(importedModule => webSocketImplName ? importedModule[webSocketImplName] : importedModule)
|
|
116
|
-
.resolve();
|
|
108
|
+
return (0, utils_1.mapMaybePromise)(importFn(moduleName), importedModule => webSocketImplName ? importedModule[webSocketImplName] : importedModule);
|
|
117
109
|
}
|
|
118
110
|
else {
|
|
119
111
|
const websocketImpl = options?.webSocketImpl || isomorphic_ws_1.default;
|
|
@@ -133,8 +125,7 @@ class UrlLoader {
|
|
|
133
125
|
return this.buildHTTPExecutor(subscriptionsEndpoint, fetch, options);
|
|
134
126
|
}
|
|
135
127
|
else {
|
|
136
|
-
const
|
|
137
|
-
const executor$ = webSocketImpl$.then(webSocketImpl => {
|
|
128
|
+
const executor$ = (0, utils_1.mapMaybePromise)(this.getWebSocketImpl(importFn, options), webSocketImpl => {
|
|
138
129
|
if (options?.subscriptionsProtocol === SubscriptionProtocol.LEGACY_WS) {
|
|
139
130
|
return this.buildWSLegacyExecutor(subscriptionsEndpoint, webSocketImpl, options);
|
|
140
131
|
}
|
|
@@ -142,17 +133,15 @@ class UrlLoader {
|
|
|
142
133
|
return this.buildWSExecutor(subscriptionsEndpoint, webSocketImpl, options?.connectionParams);
|
|
143
134
|
}
|
|
144
135
|
});
|
|
145
|
-
return request =>
|
|
136
|
+
return request => (0, utils_1.mapMaybePromise)(executor$, executor => executor(request));
|
|
146
137
|
}
|
|
147
138
|
}
|
|
148
139
|
getExecutor(endpoint, importFn, options) {
|
|
149
|
-
const fetch$ =
|
|
150
|
-
const httpExecutor$ =
|
|
151
|
-
return this.buildHTTPExecutor(endpoint, fetch, options);
|
|
152
|
-
});
|
|
140
|
+
const fetch$ = this.getFetch(options?.customFetch, importFn);
|
|
141
|
+
const httpExecutor$ = (0, utils_1.mapMaybePromise)(fetch$, fetch => this.buildHTTPExecutor(endpoint, fetch, options));
|
|
153
142
|
if (options?.subscriptionsEndpoint != null ||
|
|
154
143
|
options?.subscriptionsProtocol !== SubscriptionProtocol.SSE) {
|
|
155
|
-
const subscriptionExecutor$ =
|
|
144
|
+
const subscriptionExecutor$ = (0, utils_1.mapMaybePromise)(fetch$, fetch => {
|
|
156
145
|
const subscriptionsEndpoint = options?.subscriptionsEndpoint || endpoint;
|
|
157
146
|
return this.buildSubscriptionExecutor(subscriptionsEndpoint, fetch, importFn, options);
|
|
158
147
|
});
|
|
@@ -170,12 +159,10 @@ class UrlLoader {
|
|
|
170
159
|
return httpExecutor$;
|
|
171
160
|
}
|
|
172
161
|
}
|
|
173
|
-
return request => getExecutorByRequest(request)
|
|
174
|
-
.then(executor => executor(request))
|
|
175
|
-
.resolve();
|
|
162
|
+
return request => (0, utils_1.mapMaybePromise)(getExecutorByRequest(request), executor => executor(request));
|
|
176
163
|
}
|
|
177
164
|
else {
|
|
178
|
-
return request => httpExecutor
|
|
165
|
+
return request => (0, utils_1.mapMaybePromise)(httpExecutor$, executor => executor(request));
|
|
179
166
|
}
|
|
180
167
|
}
|
|
181
168
|
getExecutorAsync(endpoint, options) {
|
|
@@ -186,13 +173,10 @@ class UrlLoader {
|
|
|
186
173
|
}
|
|
187
174
|
handleSDL(pointer, fetch, options) {
|
|
188
175
|
const defaultMethod = this.getDefaultMethodFromOptions(options?.method, 'GET');
|
|
189
|
-
return
|
|
176
|
+
return (0, utils_1.mapMaybePromise)(fetch(pointer, {
|
|
190
177
|
method: defaultMethod,
|
|
191
178
|
headers: typeof options?.headers === 'function' ? options.headers() : options?.headers,
|
|
192
|
-
}))
|
|
193
|
-
.then(response => response.text())
|
|
194
|
-
.then(schemaString => (0, utils_1.parseGraphQLSDL)(pointer, schemaString, options))
|
|
195
|
-
.resolve();
|
|
179
|
+
}), res => (0, utils_1.mapMaybePromise)(res.text(), schemaString => (0, utils_1.parseGraphQLSDL)(pointer, schemaString, options)));
|
|
196
180
|
}
|
|
197
181
|
async load(pointer, options) {
|
|
198
182
|
if (!isCompatibleUri(pointer)) {
|
package/esm/defaultAsyncFetch.js
CHANGED
package/esm/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { buildASTSchema, buildSchema } from 'graphql';
|
|
2
2
|
import WebSocket from 'isomorphic-ws';
|
|
3
|
-
import { ValueOrPromise } from 'value-or-promise';
|
|
4
3
|
import { buildGraphQLWSExecutor } from '@graphql-tools/executor-graphql-ws';
|
|
5
4
|
import { buildHTTPExecutor, isLiveQueryOperationDefinitionNode, } from '@graphql-tools/executor-http';
|
|
6
5
|
import { buildWSLegacyExecutor } from '@graphql-tools/executor-legacy-ws';
|
|
7
|
-
import { getOperationASTFromRequest, parseGraphQLSDL, } from '@graphql-tools/utils';
|
|
6
|
+
import { getOperationASTFromRequest, isUrl, mapMaybePromise, parseGraphQLSDL, } from '@graphql-tools/utils';
|
|
8
7
|
import { schemaFromExecutor, wrapSchema } from '@graphql-tools/wrap';
|
|
9
8
|
import { defaultAsyncFetch } from './defaultAsyncFetch.js';
|
|
10
9
|
import { defaultSyncFetch } from './defaultSyncFetch.js';
|
|
@@ -29,13 +28,10 @@ export var SubscriptionProtocol;
|
|
|
29
28
|
})(SubscriptionProtocol || (SubscriptionProtocol = {}));
|
|
30
29
|
const acceptableProtocols = ['http:', 'https:', 'ws:', 'wss:'];
|
|
31
30
|
function isCompatibleUri(uri) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return acceptableProtocols.includes(url.protocol);
|
|
35
|
-
}
|
|
36
|
-
catch {
|
|
37
|
-
return false;
|
|
31
|
+
if (acceptableProtocols.some(protocol => uri.startsWith(protocol))) {
|
|
32
|
+
return isUrl(uri);
|
|
38
33
|
}
|
|
34
|
+
return false;
|
|
39
35
|
}
|
|
40
36
|
/**
|
|
41
37
|
* This loader loads a schema from a URL. The loaded schema is a fully-executable,
|
|
@@ -83,9 +79,7 @@ export class UrlLoader {
|
|
|
83
79
|
if (customFetch) {
|
|
84
80
|
if (typeof customFetch === 'string') {
|
|
85
81
|
const [moduleName, fetchFnName] = customFetch.split('#');
|
|
86
|
-
return
|
|
87
|
-
.then(module => (fetchFnName ? module[fetchFnName] : module))
|
|
88
|
-
.resolve();
|
|
82
|
+
return mapMaybePromise(importFn(moduleName), module => fetchFnName ? module[fetchFnName] : module);
|
|
89
83
|
}
|
|
90
84
|
else if (typeof customFetch === 'function') {
|
|
91
85
|
return customFetch;
|
|
@@ -107,9 +101,7 @@ export class UrlLoader {
|
|
|
107
101
|
getWebSocketImpl(importFn, options) {
|
|
108
102
|
if (typeof options?.webSocketImpl === 'string') {
|
|
109
103
|
const [moduleName, webSocketImplName] = options.webSocketImpl.split('#');
|
|
110
|
-
return
|
|
111
|
-
.then(importedModule => webSocketImplName ? importedModule[webSocketImplName] : importedModule)
|
|
112
|
-
.resolve();
|
|
104
|
+
return mapMaybePromise(importFn(moduleName), importedModule => webSocketImplName ? importedModule[webSocketImplName] : importedModule);
|
|
113
105
|
}
|
|
114
106
|
else {
|
|
115
107
|
const websocketImpl = options?.webSocketImpl || WebSocket;
|
|
@@ -129,8 +121,7 @@ export class UrlLoader {
|
|
|
129
121
|
return this.buildHTTPExecutor(subscriptionsEndpoint, fetch, options);
|
|
130
122
|
}
|
|
131
123
|
else {
|
|
132
|
-
const
|
|
133
|
-
const executor$ = webSocketImpl$.then(webSocketImpl => {
|
|
124
|
+
const executor$ = mapMaybePromise(this.getWebSocketImpl(importFn, options), webSocketImpl => {
|
|
134
125
|
if (options?.subscriptionsProtocol === SubscriptionProtocol.LEGACY_WS) {
|
|
135
126
|
return this.buildWSLegacyExecutor(subscriptionsEndpoint, webSocketImpl, options);
|
|
136
127
|
}
|
|
@@ -138,17 +129,15 @@ export class UrlLoader {
|
|
|
138
129
|
return this.buildWSExecutor(subscriptionsEndpoint, webSocketImpl, options?.connectionParams);
|
|
139
130
|
}
|
|
140
131
|
});
|
|
141
|
-
return request =>
|
|
132
|
+
return request => mapMaybePromise(executor$, executor => executor(request));
|
|
142
133
|
}
|
|
143
134
|
}
|
|
144
135
|
getExecutor(endpoint, importFn, options) {
|
|
145
|
-
const fetch$ =
|
|
146
|
-
const httpExecutor$ =
|
|
147
|
-
return this.buildHTTPExecutor(endpoint, fetch, options);
|
|
148
|
-
});
|
|
136
|
+
const fetch$ = this.getFetch(options?.customFetch, importFn);
|
|
137
|
+
const httpExecutor$ = mapMaybePromise(fetch$, fetch => this.buildHTTPExecutor(endpoint, fetch, options));
|
|
149
138
|
if (options?.subscriptionsEndpoint != null ||
|
|
150
139
|
options?.subscriptionsProtocol !== SubscriptionProtocol.SSE) {
|
|
151
|
-
const subscriptionExecutor$ =
|
|
140
|
+
const subscriptionExecutor$ = mapMaybePromise(fetch$, fetch => {
|
|
152
141
|
const subscriptionsEndpoint = options?.subscriptionsEndpoint || endpoint;
|
|
153
142
|
return this.buildSubscriptionExecutor(subscriptionsEndpoint, fetch, importFn, options);
|
|
154
143
|
});
|
|
@@ -166,12 +155,10 @@ export class UrlLoader {
|
|
|
166
155
|
return httpExecutor$;
|
|
167
156
|
}
|
|
168
157
|
}
|
|
169
|
-
return request => getExecutorByRequest(request)
|
|
170
|
-
.then(executor => executor(request))
|
|
171
|
-
.resolve();
|
|
158
|
+
return request => mapMaybePromise(getExecutorByRequest(request), executor => executor(request));
|
|
172
159
|
}
|
|
173
160
|
else {
|
|
174
|
-
return request => httpExecutor
|
|
161
|
+
return request => mapMaybePromise(httpExecutor$, executor => executor(request));
|
|
175
162
|
}
|
|
176
163
|
}
|
|
177
164
|
getExecutorAsync(endpoint, options) {
|
|
@@ -182,13 +169,10 @@ export class UrlLoader {
|
|
|
182
169
|
}
|
|
183
170
|
handleSDL(pointer, fetch, options) {
|
|
184
171
|
const defaultMethod = this.getDefaultMethodFromOptions(options?.method, 'GET');
|
|
185
|
-
return
|
|
172
|
+
return mapMaybePromise(fetch(pointer, {
|
|
186
173
|
method: defaultMethod,
|
|
187
174
|
headers: typeof options?.headers === 'function' ? options.headers() : options?.headers,
|
|
188
|
-
}))
|
|
189
|
-
.then(response => response.text())
|
|
190
|
-
.then(schemaString => parseGraphQLSDL(pointer, schemaString, options))
|
|
191
|
-
.resolve();
|
|
175
|
+
}), res => mapMaybePromise(res.text(), schemaString => parseGraphQLSDL(pointer, schemaString, options)));
|
|
192
176
|
}
|
|
193
177
|
async load(pointer, options) {
|
|
194
178
|
if (!isCompatibleUri(pointer)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/url-loader",
|
|
3
|
-
"version": "8.0.25-alpha-
|
|
3
|
+
"version": "8.0.25-alpha-20250209212603-8422ca208e29154daa75f23ffdc70e969464572b",
|
|
4
4
|
"description": "A set of utils for faster development of GraphQL tools",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
@@ -9,15 +9,14 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@graphql-tools/executor-graphql-ws": "^1.3.2",
|
|
11
11
|
"@graphql-tools/executor-http": "^1.1.9",
|
|
12
|
-
"@graphql-tools/executor-legacy-ws": "1.1.11-alpha-
|
|
13
|
-
"@graphql-tools/utils": "10.8.0-alpha-
|
|
12
|
+
"@graphql-tools/executor-legacy-ws": "1.1.11-alpha-20250209212603-8422ca208e29154daa75f23ffdc70e969464572b",
|
|
13
|
+
"@graphql-tools/utils": "10.8.0-alpha-20250209212603-8422ca208e29154daa75f23ffdc70e969464572b",
|
|
14
14
|
"@graphql-tools/wrap": "^10.0.16",
|
|
15
15
|
"@types/ws": "^8.0.0",
|
|
16
16
|
"@whatwg-node/fetch": "^0.10.0",
|
|
17
17
|
"isomorphic-ws": "^5.0.0",
|
|
18
18
|
"sync-fetch": "0.6.0-2",
|
|
19
19
|
"tslib": "^2.4.0",
|
|
20
|
-
"value-or-promise": "^1.0.11",
|
|
21
20
|
"ws": "^8.17.1"
|
|
22
21
|
},
|
|
23
22
|
"repository": {
|