@graphql-tools/url-loader 7.14.3 → 7.16.0-alpha-20220909124100-cb222376
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/index.js +13 -15
- package/esm/index.js +13 -15
- package/package.json +1 -1
- package/typings/index.d.cts +1 -2
- package/typings/index.d.ts +1 -2
package/cjs/index.js
CHANGED
|
@@ -11,7 +11,6 @@ const graphql_ws_1 = require("graphql-ws");
|
|
|
11
11
|
const isomorphic_ws_1 = tslib_1.__importDefault(require("isomorphic-ws"));
|
|
12
12
|
const extract_files_1 = require("extract-files");
|
|
13
13
|
const value_or_promise_1 = require("value-or-promise");
|
|
14
|
-
const graphql_live_query_1 = require("@n1ru4l/graphql-live-query");
|
|
15
14
|
const defaultAsyncFetch_js_1 = require("./defaultAsyncFetch.js");
|
|
16
15
|
const defaultSyncFetch_js_1 = require("./defaultSyncFetch.js");
|
|
17
16
|
const handleMultipartMixedResponse_js_1 = require("./handleMultipartMixedResponse.js");
|
|
@@ -21,6 +20,10 @@ const fetch_1 = require("@whatwg-node/fetch");
|
|
|
21
20
|
const utils_js_1 = require("./utils.js");
|
|
22
21
|
const asyncImport = (moduleName) => Promise.resolve().then(() => tslib_1.__importStar(require(moduleName)));
|
|
23
22
|
const syncImport = (moduleName) => require(moduleName);
|
|
23
|
+
const isLiveQueryOperationDefinitionNode = (0, utils_1.memoize1)(function isLiveQueryOperationDefinitionNode(node) {
|
|
24
|
+
var _a;
|
|
25
|
+
return (_a = node.directives) === null || _a === void 0 ? void 0 : _a.some(directive => directive.name.value === 'live');
|
|
26
|
+
});
|
|
24
27
|
var SubscriptionProtocol;
|
|
25
28
|
(function (SubscriptionProtocol) {
|
|
26
29
|
SubscriptionProtocol["WS"] = "WS";
|
|
@@ -156,7 +159,7 @@ class UrlLoader {
|
|
|
156
159
|
ws: 'http',
|
|
157
160
|
});
|
|
158
161
|
const executor = (request) => {
|
|
159
|
-
var _a, _b
|
|
162
|
+
var _a, _b;
|
|
160
163
|
const controller = (0, addCancelToResponseStream_js_1.cancelNeeded)() ? new fetch_1.AbortController() : undefined;
|
|
161
164
|
let method = defaultMethod;
|
|
162
165
|
const operationAst = (0, utils_1.getOperationASTFromRequest)(request);
|
|
@@ -164,18 +167,15 @@ class UrlLoader {
|
|
|
164
167
|
if ((options === null || options === void 0 ? void 0 : options.useGETForQueries) && operationType === 'query') {
|
|
165
168
|
method = 'GET';
|
|
166
169
|
}
|
|
167
|
-
let accept = 'application/json';
|
|
168
|
-
if (operationType === 'subscription' ||
|
|
170
|
+
let accept = 'application/graphql-response+json, application/json, multipart/mixed';
|
|
171
|
+
if (operationType === 'subscription' || isLiveQueryOperationDefinitionNode(operationAst)) {
|
|
169
172
|
method = 'GET';
|
|
170
173
|
accept = 'text/event-stream';
|
|
171
174
|
}
|
|
172
|
-
|
|
173
|
-
accept += ', multipart/mixed';
|
|
174
|
-
}
|
|
175
|
-
const endpoint = ((_b = request.extensions) === null || _b === void 0 ? void 0 : _b.endpoint) || HTTP_URL;
|
|
175
|
+
const endpoint = ((_a = request.extensions) === null || _a === void 0 ? void 0 : _a.endpoint) || HTTP_URL;
|
|
176
176
|
const headers = Object.assign({
|
|
177
177
|
accept,
|
|
178
|
-
}, options === null || options === void 0 ? void 0 : options.headers, ((
|
|
178
|
+
}, options === null || options === void 0 ? void 0 : options.headers, ((_b = request.extensions) === null || _b === void 0 ? void 0 : _b.headers) || {});
|
|
179
179
|
const query = (0, graphql_1.print)(request.document);
|
|
180
180
|
const requestBody = {
|
|
181
181
|
query,
|
|
@@ -191,7 +191,6 @@ class UrlLoader {
|
|
|
191
191
|
}
|
|
192
192
|
}, options.timeout);
|
|
193
193
|
}
|
|
194
|
-
const credentials = (options === null || options === void 0 ? void 0 : options.credentials) !== 'disable' ? (options === null || options === void 0 ? void 0 : options.credentials) || 'same-origin' : null;
|
|
195
194
|
return new value_or_promise_1.ValueOrPromise(() => {
|
|
196
195
|
switch (method) {
|
|
197
196
|
case 'GET':
|
|
@@ -201,7 +200,7 @@ class UrlLoader {
|
|
|
201
200
|
});
|
|
202
201
|
return fetch(finalUrl, {
|
|
203
202
|
method: 'GET',
|
|
204
|
-
...(credentials != null ? { credentials } : {}),
|
|
203
|
+
...((options === null || options === void 0 ? void 0 : options.credentials) != null ? { credentials: options.credentials } : {}),
|
|
205
204
|
headers,
|
|
206
205
|
signal: controller === null || controller === void 0 ? void 0 : controller.signal,
|
|
207
206
|
}, request.context, request.info);
|
|
@@ -210,7 +209,7 @@ class UrlLoader {
|
|
|
210
209
|
return new value_or_promise_1.ValueOrPromise(() => this.createFormDataFromVariables(requestBody))
|
|
211
210
|
.then(body => fetch(endpoint, {
|
|
212
211
|
method: 'POST',
|
|
213
|
-
...(credentials != null ? { credentials } : {}),
|
|
212
|
+
...((options === null || options === void 0 ? void 0 : options.credentials) != null ? { credentials: options.credentials } : {}),
|
|
214
213
|
body,
|
|
215
214
|
headers: {
|
|
216
215
|
...headers,
|
|
@@ -223,7 +222,7 @@ class UrlLoader {
|
|
|
223
222
|
else {
|
|
224
223
|
return fetch(endpoint, {
|
|
225
224
|
method: 'POST',
|
|
226
|
-
...(credentials != null ? { credentials } : {}),
|
|
225
|
+
...((options === null || options === void 0 ? void 0 : options.credentials) != null ? { credentials: options.credentials } : {}),
|
|
227
226
|
body: JSON.stringify(requestBody),
|
|
228
227
|
headers: {
|
|
229
228
|
'content-type': 'application/json',
|
|
@@ -504,8 +503,7 @@ class UrlLoader {
|
|
|
504
503
|
// eslint-disable-next-line no-inner-declarations
|
|
505
504
|
function getExecutorByRequest(request) {
|
|
506
505
|
const operationAst = (0, utils_1.getOperationASTFromRequest)(request);
|
|
507
|
-
if (operationAst.operation === 'subscription' ||
|
|
508
|
-
(0, graphql_live_query_1.isLiveQueryOperationDefinitionNode)(operationAst, request.variables)) {
|
|
506
|
+
if (operationAst.operation === 'subscription' || isLiveQueryOperationDefinitionNode(operationAst)) {
|
|
509
507
|
return subscriptionExecutor$;
|
|
510
508
|
}
|
|
511
509
|
else {
|
package/esm/index.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/* eslint-disable no-case-declarations */
|
|
2
2
|
/// <reference lib="dom" />
|
|
3
3
|
import { print, stripIgnoredCharacters, buildASTSchema, buildSchema, } from 'graphql';
|
|
4
|
-
import { observableToAsyncIterable, isAsyncIterable, parseGraphQLSDL, getOperationASTFromRequest, } from '@graphql-tools/utils';
|
|
4
|
+
import { observableToAsyncIterable, isAsyncIterable, parseGraphQLSDL, getOperationASTFromRequest, memoize1, } from '@graphql-tools/utils';
|
|
5
5
|
import { introspectSchema, wrapSchema } from '@graphql-tools/wrap';
|
|
6
6
|
import { createClient } from 'graphql-ws';
|
|
7
7
|
import WebSocket from 'isomorphic-ws';
|
|
8
8
|
import { extractFiles, isExtractableFile } from 'extract-files';
|
|
9
9
|
import { ValueOrPromise } from 'value-or-promise';
|
|
10
|
-
import { isLiveQueryOperationDefinitionNode } from '@n1ru4l/graphql-live-query';
|
|
11
10
|
import { defaultAsyncFetch } from './defaultAsyncFetch.js';
|
|
12
11
|
import { defaultSyncFetch } from './defaultSyncFetch.js';
|
|
13
12
|
import { handleMultipartMixedResponse } from './handleMultipartMixedResponse.js';
|
|
@@ -17,6 +16,10 @@ import { AbortController, FormData, File } from '@whatwg-node/fetch';
|
|
|
17
16
|
import { isBlob, isGraphQLUpload, isPromiseLike, LEGACY_WS } from './utils.js';
|
|
18
17
|
const asyncImport = (moduleName) => import(moduleName);
|
|
19
18
|
const syncImport = (moduleName) => require(moduleName);
|
|
19
|
+
const isLiveQueryOperationDefinitionNode = memoize1(function isLiveQueryOperationDefinitionNode(node) {
|
|
20
|
+
var _a;
|
|
21
|
+
return (_a = node.directives) === null || _a === void 0 ? void 0 : _a.some(directive => directive.name.value === 'live');
|
|
22
|
+
});
|
|
20
23
|
export var SubscriptionProtocol;
|
|
21
24
|
(function (SubscriptionProtocol) {
|
|
22
25
|
SubscriptionProtocol["WS"] = "WS";
|
|
@@ -152,7 +155,7 @@ export class UrlLoader {
|
|
|
152
155
|
ws: 'http',
|
|
153
156
|
});
|
|
154
157
|
const executor = (request) => {
|
|
155
|
-
var _a, _b
|
|
158
|
+
var _a, _b;
|
|
156
159
|
const controller = cancelNeeded() ? new AbortController() : undefined;
|
|
157
160
|
let method = defaultMethod;
|
|
158
161
|
const operationAst = getOperationASTFromRequest(request);
|
|
@@ -160,18 +163,15 @@ export class UrlLoader {
|
|
|
160
163
|
if ((options === null || options === void 0 ? void 0 : options.useGETForQueries) && operationType === 'query') {
|
|
161
164
|
method = 'GET';
|
|
162
165
|
}
|
|
163
|
-
let accept = 'application/json';
|
|
166
|
+
let accept = 'application/graphql-response+json, application/json, multipart/mixed';
|
|
164
167
|
if (operationType === 'subscription' || isLiveQueryOperationDefinitionNode(operationAst)) {
|
|
165
168
|
method = 'GET';
|
|
166
169
|
accept = 'text/event-stream';
|
|
167
170
|
}
|
|
168
|
-
|
|
169
|
-
accept += ', multipart/mixed';
|
|
170
|
-
}
|
|
171
|
-
const endpoint = ((_b = request.extensions) === null || _b === void 0 ? void 0 : _b.endpoint) || HTTP_URL;
|
|
171
|
+
const endpoint = ((_a = request.extensions) === null || _a === void 0 ? void 0 : _a.endpoint) || HTTP_URL;
|
|
172
172
|
const headers = Object.assign({
|
|
173
173
|
accept,
|
|
174
|
-
}, options === null || options === void 0 ? void 0 : options.headers, ((
|
|
174
|
+
}, options === null || options === void 0 ? void 0 : options.headers, ((_b = request.extensions) === null || _b === void 0 ? void 0 : _b.headers) || {});
|
|
175
175
|
const query = print(request.document);
|
|
176
176
|
const requestBody = {
|
|
177
177
|
query,
|
|
@@ -187,7 +187,6 @@ export class UrlLoader {
|
|
|
187
187
|
}
|
|
188
188
|
}, options.timeout);
|
|
189
189
|
}
|
|
190
|
-
const credentials = (options === null || options === void 0 ? void 0 : options.credentials) !== 'disable' ? (options === null || options === void 0 ? void 0 : options.credentials) || 'same-origin' : null;
|
|
191
190
|
return new ValueOrPromise(() => {
|
|
192
191
|
switch (method) {
|
|
193
192
|
case 'GET':
|
|
@@ -197,7 +196,7 @@ export class UrlLoader {
|
|
|
197
196
|
});
|
|
198
197
|
return fetch(finalUrl, {
|
|
199
198
|
method: 'GET',
|
|
200
|
-
...(credentials != null ? { credentials } : {}),
|
|
199
|
+
...((options === null || options === void 0 ? void 0 : options.credentials) != null ? { credentials: options.credentials } : {}),
|
|
201
200
|
headers,
|
|
202
201
|
signal: controller === null || controller === void 0 ? void 0 : controller.signal,
|
|
203
202
|
}, request.context, request.info);
|
|
@@ -206,7 +205,7 @@ export class UrlLoader {
|
|
|
206
205
|
return new ValueOrPromise(() => this.createFormDataFromVariables(requestBody))
|
|
207
206
|
.then(body => fetch(endpoint, {
|
|
208
207
|
method: 'POST',
|
|
209
|
-
...(credentials != null ? { credentials } : {}),
|
|
208
|
+
...((options === null || options === void 0 ? void 0 : options.credentials) != null ? { credentials: options.credentials } : {}),
|
|
210
209
|
body,
|
|
211
210
|
headers: {
|
|
212
211
|
...headers,
|
|
@@ -219,7 +218,7 @@ export class UrlLoader {
|
|
|
219
218
|
else {
|
|
220
219
|
return fetch(endpoint, {
|
|
221
220
|
method: 'POST',
|
|
222
|
-
...(credentials != null ? { credentials } : {}),
|
|
221
|
+
...((options === null || options === void 0 ? void 0 : options.credentials) != null ? { credentials: options.credentials } : {}),
|
|
223
222
|
body: JSON.stringify(requestBody),
|
|
224
223
|
headers: {
|
|
225
224
|
'content-type': 'application/json',
|
|
@@ -500,8 +499,7 @@ export class UrlLoader {
|
|
|
500
499
|
// eslint-disable-next-line no-inner-declarations
|
|
501
500
|
function getExecutorByRequest(request) {
|
|
502
501
|
const operationAst = getOperationASTFromRequest(request);
|
|
503
|
-
if (operationAst.operation === 'subscription' ||
|
|
504
|
-
isLiveQueryOperationDefinitionNode(operationAst, request.variables)) {
|
|
502
|
+
if (operationAst.operation === 'subscription' || isLiveQueryOperationDefinitionNode(operationAst)) {
|
|
505
503
|
return subscriptionExecutor$;
|
|
506
504
|
}
|
|
507
505
|
else {
|
package/package.json
CHANGED
package/typings/index.d.cts
CHANGED
|
@@ -89,10 +89,9 @@ export interface LoadFromUrlOptions extends BaseLoaderOptions, Partial<Introspec
|
|
|
89
89
|
timeout?: number;
|
|
90
90
|
/**
|
|
91
91
|
* Request Credentials (default: 'same-origin')
|
|
92
|
-
* You can pass `disable` if you don't want this to be set in `Request`
|
|
93
92
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials
|
|
94
93
|
*/
|
|
95
|
-
credentials?: RequestCredentials
|
|
94
|
+
credentials?: RequestCredentials;
|
|
96
95
|
/**
|
|
97
96
|
* Connection Parameters for WebSockets connection
|
|
98
97
|
*/
|
package/typings/index.d.ts
CHANGED
|
@@ -89,10 +89,9 @@ export interface LoadFromUrlOptions extends BaseLoaderOptions, Partial<Introspec
|
|
|
89
89
|
timeout?: number;
|
|
90
90
|
/**
|
|
91
91
|
* Request Credentials (default: 'same-origin')
|
|
92
|
-
* You can pass `disable` if you don't want this to be set in `Request`
|
|
93
92
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials
|
|
94
93
|
*/
|
|
95
|
-
credentials?: RequestCredentials
|
|
94
|
+
credentials?: RequestCredentials;
|
|
96
95
|
/**
|
|
97
96
|
* Connection Parameters for WebSockets connection
|
|
98
97
|
*/
|