@graphql-tools/executor-http 1.1.9 → 1.1.10-alpha-e8c01415b3b19676af5ff8b818bc152e3293f9e4

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 (41) hide show
  1. package/CHANGELOG.md +480 -0
  2. package/dist/index.cjs +546 -0
  3. package/{typings → dist}/index.d.cts +28 -25
  4. package/{typings → dist}/index.d.ts +28 -25
  5. package/dist/index.js +543 -0
  6. package/package.json +38 -46
  7. package/cjs/createFormDataFromVariables.js +0 -76
  8. package/cjs/createTimeoutSignal.js +0 -1
  9. package/cjs/defaultPrintFn.js +0 -14
  10. package/cjs/handleEventStreamResponse.js +0 -55
  11. package/cjs/handleMultipartMixedResponse.js +0 -48
  12. package/cjs/index.js +0 -314
  13. package/cjs/isGraphQLUpload.js +0 -7
  14. package/cjs/isLiveQueryOperationDefinitionNode.js +0 -8
  15. package/cjs/package.json +0 -1
  16. package/cjs/prepareGETUrl.js +0 -26
  17. package/esm/createFormDataFromVariables.js +0 -72
  18. package/esm/createTimeoutSignal.js +0 -1
  19. package/esm/defaultPrintFn.js +0 -10
  20. package/esm/handleEventStreamResponse.js +0 -50
  21. package/esm/handleMultipartMixedResponse.js +0 -44
  22. package/esm/index.js +0 -310
  23. package/esm/isGraphQLUpload.js +0 -3
  24. package/esm/isLiveQueryOperationDefinitionNode.js +0 -5
  25. package/esm/prepareGETUrl.js +0 -22
  26. package/typings/createFormDataFromVariables.d.cts +0 -10
  27. package/typings/createFormDataFromVariables.d.ts +0 -10
  28. package/typings/createTimeoutSignal.d.cts +0 -0
  29. package/typings/createTimeoutSignal.d.ts +0 -0
  30. package/typings/defaultPrintFn.d.cts +0 -2
  31. package/typings/defaultPrintFn.d.ts +0 -2
  32. package/typings/handleEventStreamResponse.d.cts +0 -4
  33. package/typings/handleEventStreamResponse.d.ts +0 -4
  34. package/typings/handleMultipartMixedResponse.d.cts +0 -2
  35. package/typings/handleMultipartMixedResponse.d.ts +0 -2
  36. package/typings/isGraphQLUpload.d.cts +0 -9
  37. package/typings/isGraphQLUpload.d.ts +0 -9
  38. package/typings/isLiveQueryOperationDefinitionNode.d.cts +0 -2
  39. package/typings/isLiveQueryOperationDefinitionNode.d.ts +0 -2
  40. package/typings/prepareGETUrl.d.cts +0 -7
  41. package/typings/prepareGETUrl.d.ts +0 -7
package/package.json CHANGED
@@ -1,66 +1,58 @@
1
1
  {
2
2
  "name": "@graphql-tools/executor-http",
3
- "version": "1.1.9",
3
+ "version": "1.1.10-alpha-e8c01415b3b19676af5ff8b818bc152e3293f9e4",
4
+ "type": "module",
4
5
  "description": "A set of utils for faster development of GraphQL tools",
5
- "sideEffects": false,
6
- "peerDependencies": {
7
- "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
8
- },
9
- "dependencies": {
10
- "@graphql-tools/utils": "^10.5.6",
11
- "@repeaterjs/repeater": "^3.0.4",
12
- "@whatwg-node/fetch": "^0.10.0",
13
- "extract-files": "^11.0.0",
14
- "meros": "^1.2.1",
15
- "tslib": "^2.4.0",
16
- "value-or-promise": "^1.0.12"
17
- },
18
6
  "repository": {
19
7
  "type": "git",
20
- "url": "ardatan/graphql-tools",
8
+ "url": "graphql-hive/gateway",
21
9
  "directory": "packages/executors/http"
22
10
  },
23
11
  "author": "Arda TANRIKULU <ardatanrikulu@gmail.com>",
24
12
  "license": "MIT",
25
13
  "engines": {
26
- "node": ">=16.0.0"
14
+ "node": ">=18.0.0"
27
15
  },
28
- "main": "cjs/index.js",
29
- "module": "esm/index.js",
30
- "typings": "typings/index.d.ts",
31
- "typescript": {
32
- "definition": "typings/index.d.ts"
33
- },
34
- "type": "module",
16
+ "main": "./dist/index.js",
35
17
  "exports": {
36
18
  ".": {
37
19
  "require": {
38
- "types": "./typings/index.d.cts",
39
- "default": "./cjs/index.js"
20
+ "types": "./dist/index.d.cts",
21
+ "default": "./dist/index.cjs"
40
22
  },
41
23
  "import": {
42
- "types": "./typings/index.d.ts",
43
- "default": "./esm/index.js"
44
- },
45
- "default": {
46
- "types": "./typings/index.d.ts",
47
- "default": "./esm/index.js"
48
- }
49
- },
50
- "./*": {
51
- "require": {
52
- "types": "./typings/*.d.cts",
53
- "default": "./cjs/*.js"
54
- },
55
- "import": {
56
- "types": "./typings/*.d.ts",
57
- "default": "./esm/*.js"
58
- },
59
- "default": {
60
- "types": "./typings/*.d.ts",
61
- "default": "./esm/*.js"
24
+ "types": "./dist/index.d.ts",
25
+ "default": "./dist/index.js"
62
26
  }
63
27
  },
64
28
  "./package.json": "./package.json"
65
- }
29
+ },
30
+ "types": "./dist/index.d.ts",
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "scripts": {
35
+ "build": "pkgroll --clean-dist",
36
+ "prepack": "yarn build"
37
+ },
38
+ "peerDependencies": {
39
+ "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
40
+ },
41
+ "dependencies": {
42
+ "@graphql-tools/utils": "^10.5.6",
43
+ "@repeaterjs/repeater": "^3.0.4",
44
+ "@whatwg-node/fetch": "^0.10.0",
45
+ "extract-files": "^11.0.0",
46
+ "meros": "^1.2.1",
47
+ "tslib": "^2.4.0",
48
+ "value-or-promise": "^1.0.12"
49
+ },
50
+ "devDependencies": {
51
+ "@types/extract-files": "8.1.3",
52
+ "@whatwg-node/disposablestack": "^0.0.5",
53
+ "graphql": "^16.9.0",
54
+ "graphql-yoga": "^5.8.0",
55
+ "pkgroll": "2.5.1"
56
+ },
57
+ "sideEffects": false
66
58
  }
@@ -1,76 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createFormDataFromVariables = void 0;
4
- const extract_files_1 = require("extract-files");
5
- const value_or_promise_1 = require("value-or-promise");
6
- const utils_1 = require("@graphql-tools/utils");
7
- const fetch_1 = require("@whatwg-node/fetch");
8
- const isGraphQLUpload_js_1 = require("./isGraphQLUpload.js");
9
- function createFormDataFromVariables({ query, variables, operationName, extensions, }, { File: FileCtor = fetch_1.File, FormData: FormDataCtor = fetch_1.FormData, }) {
10
- const vars = Object.assign({}, variables);
11
- const { clone, files } = (0, extract_files_1.extractFiles)(vars, 'variables', ((v) => (0, extract_files_1.isExtractableFile)(v) ||
12
- v?.promise ||
13
- (0, utils_1.isAsyncIterable)(v) ||
14
- v?.then ||
15
- typeof v?.arrayBuffer === 'function'));
16
- if (files.size === 0) {
17
- return JSON.stringify({
18
- query,
19
- variables,
20
- operationName,
21
- extensions,
22
- }, null, 2);
23
- }
24
- const map = {};
25
- const uploads = [];
26
- let currIndex = 0;
27
- for (const [file, curr] of files) {
28
- map[currIndex] = curr;
29
- uploads[currIndex] = file;
30
- currIndex++;
31
- }
32
- const form = new FormDataCtor();
33
- form.append('operations', JSON.stringify({
34
- query,
35
- variables: clone,
36
- operationName,
37
- extensions,
38
- }));
39
- form.append('map', JSON.stringify(map, null, 2));
40
- function handleUpload(upload, i) {
41
- const indexStr = i.toString();
42
- if (upload != null) {
43
- const filename = upload.filename || upload.name || upload.path || `blob-${indexStr}`;
44
- if ((0, utils_1.isPromise)(upload)) {
45
- return upload.then((resolvedUpload) => handleUpload(resolvedUpload, i));
46
- // If Blob
47
- }
48
- else if (isBlob(upload)) {
49
- form.append(indexStr, upload, filename);
50
- }
51
- else if ((0, isGraphQLUpload_js_1.isGraphQLUpload)(upload)) {
52
- const stream = upload.createReadStream();
53
- const chunks = [];
54
- return Promise.resolve().then(async () => {
55
- for await (const chunk of stream) {
56
- if (chunk) {
57
- chunks.push(...chunk);
58
- }
59
- }
60
- const blobPart = new Uint8Array(chunks);
61
- form.append(indexStr, new FileCtor([blobPart], filename, { type: upload.mimetype }), filename);
62
- });
63
- }
64
- else {
65
- form.append(indexStr, new FileCtor([upload], filename), filename);
66
- }
67
- }
68
- }
69
- return value_or_promise_1.ValueOrPromise.all(uploads.map((upload, i) => new value_or_promise_1.ValueOrPromise(() => handleUpload(upload, i))))
70
- .then(() => form)
71
- .resolve();
72
- }
73
- exports.createFormDataFromVariables = createFormDataFromVariables;
74
- function isBlob(obj) {
75
- return typeof obj.arrayBuffer === 'function';
76
- }
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultPrintFn = void 0;
4
- const graphql_1 = require("graphql");
5
- const printCache = new WeakMap();
6
- function defaultPrintFn(document) {
7
- let printed = printCache.get(document);
8
- if (!printed) {
9
- printed = (0, graphql_1.stripIgnoredCharacters)((0, graphql_1.print)(document));
10
- printCache.set(document, printed);
11
- }
12
- return printed;
13
- }
14
- exports.defaultPrintFn = defaultPrintFn;
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleEventStreamResponse = exports.isReadableStream = void 0;
4
- const utils_1 = require("@graphql-tools/utils");
5
- const repeater_1 = require("@repeaterjs/repeater");
6
- const fetch_1 = require("@whatwg-node/fetch");
7
- const DELIM = '\n\n';
8
- function isReadableStream(value) {
9
- return value && typeof value.getReader === 'function';
10
- }
11
- exports.isReadableStream = isReadableStream;
12
- function handleEventStreamResponse(response) {
13
- // node-fetch returns body as a promise so we need to resolve it
14
- const body = response.body;
15
- if (!isReadableStream(body)) {
16
- throw new Error('Response body is expected to be a readable stream but got; ' + (0, utils_1.inspect)(body));
17
- }
18
- return new repeater_1.Repeater((push, stop) => {
19
- const decoder = new fetch_1.TextDecoder();
20
- const reader = body.getReader();
21
- reader.closed.then(stop).catch(stop); // we dont use `finally` because we want to catch errors
22
- stop.finally(() => reader.cancel());
23
- let currChunk = '';
24
- async function pump() {
25
- const { done, value: chunk } = await reader.read();
26
- if (done) {
27
- return stop();
28
- }
29
- currChunk += typeof chunk === 'string' ? chunk : decoder.decode(chunk);
30
- for (;;) {
31
- const delimIndex = currChunk.indexOf(DELIM);
32
- if (delimIndex === -1) {
33
- // incomplete message, wait for more chunks
34
- break;
35
- }
36
- const msg = currChunk.slice(0, delimIndex); // whole message
37
- currChunk = currChunk.slice(delimIndex + DELIM.length); // remainder
38
- // data
39
- const dataStr = msg.split('data:')[1]?.trim();
40
- if (dataStr) {
41
- const data = JSON.parse(dataStr);
42
- await push(data.payload || data);
43
- }
44
- // event
45
- const event = msg.split('event:')[1]?.trim();
46
- if (event === 'complete') {
47
- return stop();
48
- }
49
- }
50
- return pump();
51
- }
52
- return pump();
53
- });
54
- }
55
- exports.handleEventStreamResponse = handleEventStreamResponse;
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleMultipartMixedResponse = void 0;
4
- const browser_1 = require("meros/browser");
5
- const node_1 = require("meros/node");
6
- const utils_1 = require("@graphql-tools/utils");
7
- function isIncomingMessage(body) {
8
- return body != null && typeof body === 'object' && 'pipe' in body;
9
- }
10
- async function handleMultipartMixedResponse(response) {
11
- const body = response.body;
12
- const contentType = response.headers.get('content-type') || '';
13
- let asyncIterator;
14
- if (isIncomingMessage(body)) {
15
- // Meros/node expects headers as an object map with the content-type prop
16
- body.headers = {
17
- 'content-type': contentType,
18
- };
19
- // And it expects `IncomingMessage` and `node-fetch` returns `body` as `Promise<PassThrough>`
20
- const result = await (0, node_1.meros)(body);
21
- if ('next' in result) {
22
- asyncIterator = result;
23
- }
24
- }
25
- else {
26
- // Nothing is needed for regular `Response`.
27
- const result = await (0, browser_1.meros)(response);
28
- if ('next' in result) {
29
- asyncIterator = result;
30
- }
31
- }
32
- const executionResult = {};
33
- if (asyncIterator == null) {
34
- return executionResult;
35
- }
36
- const resultStream = (0, utils_1.mapAsyncIterator)(asyncIterator, (part) => {
37
- if (part.json) {
38
- const incrementalResult = part.body;
39
- (0, utils_1.mergeIncrementalResult)({
40
- incrementalResult,
41
- executionResult,
42
- });
43
- return executionResult;
44
- }
45
- });
46
- return resultStream;
47
- }
48
- exports.handleMultipartMixedResponse = handleMultipartMixedResponse;
package/cjs/index.js DELETED
@@ -1,314 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isLiveQueryOperationDefinitionNode = exports.buildHTTPExecutor = void 0;
4
- const value_or_promise_1 = require("value-or-promise");
5
- const utils_1 = require("@graphql-tools/utils");
6
- const fetch_1 = require("@whatwg-node/fetch");
7
- const createFormDataFromVariables_js_1 = require("./createFormDataFromVariables.js");
8
- const defaultPrintFn_js_1 = require("./defaultPrintFn.js");
9
- const handleEventStreamResponse_js_1 = require("./handleEventStreamResponse.js");
10
- const handleMultipartMixedResponse_js_1 = require("./handleMultipartMixedResponse.js");
11
- const isLiveQueryOperationDefinitionNode_js_1 = require("./isLiveQueryOperationDefinitionNode.js");
12
- Object.defineProperty(exports, "isLiveQueryOperationDefinitionNode", { enumerable: true, get: function () { return isLiveQueryOperationDefinitionNode_js_1.isLiveQueryOperationDefinitionNode; } });
13
- const prepareGETUrl_js_1 = require("./prepareGETUrl.js");
14
- function buildHTTPExecutor(options) {
15
- const printFn = options?.print ?? defaultPrintFn_js_1.defaultPrintFn;
16
- let disposeCtrl;
17
- const baseExecutor = (request) => {
18
- if (disposeCtrl?.signal.aborted) {
19
- return createResultForAbort(disposeCtrl.signal);
20
- }
21
- const fetchFn = request.extensions?.fetch ?? options?.fetch ?? fetch_1.fetch;
22
- let method = request.extensions?.method || options?.method;
23
- const operationAst = (0, utils_1.getOperationASTFromRequest)(request);
24
- const operationType = operationAst.operation;
25
- if ((options?.useGETForQueries || request.extensions?.useGETForQueries) &&
26
- operationType === 'query') {
27
- method = 'GET';
28
- }
29
- let accept = 'application/graphql-response+json, application/json, multipart/mixed';
30
- if (operationType === 'subscription' || (0, isLiveQueryOperationDefinitionNode_js_1.isLiveQueryOperationDefinitionNode)(operationAst)) {
31
- method ||= 'GET';
32
- accept = 'text/event-stream';
33
- }
34
- else {
35
- method ||= 'POST';
36
- }
37
- const endpoint = request.extensions?.endpoint || options?.endpoint || '/graphql';
38
- const headers = { accept };
39
- if (options?.headers) {
40
- Object.assign(headers, typeof options?.headers === 'function' ? options.headers(request) : options?.headers);
41
- }
42
- if (request.extensions?.headers) {
43
- const { headers: headersFromExtensions, ...restExtensions } = request.extensions;
44
- Object.assign(headers, headersFromExtensions);
45
- request.extensions = restExtensions;
46
- }
47
- const query = printFn(request.document);
48
- let signal = disposeCtrl?.signal;
49
- let clearTimeoutFn = () => { };
50
- if (options?.timeout) {
51
- const timeoutCtrl = new AbortController();
52
- signal = timeoutCtrl.signal;
53
- disposeCtrl?.signal.addEventListener('abort', clearTimeoutFn);
54
- const timeoutId = setTimeout(() => {
55
- if (!timeoutCtrl.signal.aborted) {
56
- timeoutCtrl.abort('timeout');
57
- }
58
- disposeCtrl?.signal.removeEventListener('abort', clearTimeoutFn);
59
- }, options.timeout);
60
- clearTimeoutFn = () => {
61
- clearTimeout(timeoutId);
62
- };
63
- }
64
- const upstreamErrorExtensions = {
65
- request: {
66
- method,
67
- },
68
- response: {},
69
- };
70
- return new value_or_promise_1.ValueOrPromise(() => {
71
- switch (method) {
72
- case 'GET': {
73
- const finalUrl = (0, prepareGETUrl_js_1.prepareGETUrl)({
74
- baseUrl: endpoint,
75
- query,
76
- variables: request.variables,
77
- operationName: request.operationName,
78
- extensions: request.extensions,
79
- });
80
- const fetchOptions = {
81
- method: 'GET',
82
- headers,
83
- signal,
84
- };
85
- if (options?.credentials != null) {
86
- fetchOptions.credentials = options.credentials;
87
- }
88
- upstreamErrorExtensions.request.url = finalUrl;
89
- return fetchFn(finalUrl, fetchOptions, request.context, request.info);
90
- }
91
- case 'POST': {
92
- const body = {
93
- query,
94
- variables: request.variables,
95
- operationName: request.operationName,
96
- extensions: request.extensions,
97
- };
98
- upstreamErrorExtensions.request.body = body;
99
- return new value_or_promise_1.ValueOrPromise(() => (0, createFormDataFromVariables_js_1.createFormDataFromVariables)(body, {
100
- File: options?.File,
101
- FormData: options?.FormData,
102
- }))
103
- .then(body => {
104
- if (typeof body === 'string' && !headers['content-type']) {
105
- upstreamErrorExtensions.request.body = body;
106
- headers['content-type'] = 'application/json';
107
- }
108
- const fetchOptions = {
109
- method: 'POST',
110
- body,
111
- headers,
112
- signal,
113
- };
114
- if (options?.credentials != null) {
115
- fetchOptions.credentials = options.credentials;
116
- }
117
- return fetchFn(endpoint, fetchOptions, request.context, request.info);
118
- })
119
- .resolve();
120
- }
121
- }
122
- })
123
- .then((fetchResult) => {
124
- upstreamErrorExtensions.response.status = fetchResult.status;
125
- upstreamErrorExtensions.response.statusText = fetchResult.statusText;
126
- Object.defineProperty(upstreamErrorExtensions.response, 'headers', {
127
- get() {
128
- return Object.fromEntries(fetchResult.headers.entries());
129
- },
130
- });
131
- clearTimeoutFn();
132
- // Retry should respect HTTP Errors
133
- if (options?.retry != null && !fetchResult.status.toString().startsWith('2')) {
134
- throw new Error(fetchResult.statusText || `Upstream HTTP Error: ${fetchResult.status}`);
135
- }
136
- const contentType = fetchResult.headers.get('content-type');
137
- if (contentType?.includes('text/event-stream')) {
138
- return (0, handleEventStreamResponse_js_1.handleEventStreamResponse)(fetchResult);
139
- }
140
- else if (contentType?.includes('multipart/mixed')) {
141
- return (0, handleMultipartMixedResponse_js_1.handleMultipartMixedResponse)(fetchResult);
142
- }
143
- return fetchResult.text();
144
- })
145
- .then(result => {
146
- if (typeof result === 'string') {
147
- upstreamErrorExtensions.response.body = result;
148
- if (result) {
149
- try {
150
- const parsedResult = JSON.parse(result);
151
- upstreamErrorExtensions.response.body = parsedResult;
152
- if (parsedResult.data == null &&
153
- (parsedResult.errors == null || parsedResult.errors.length === 0)) {
154
- return {
155
- errors: [
156
- (0, utils_1.createGraphQLError)('Unexpected empty "data" and "errors" fields in result: ' + result, {
157
- extensions: upstreamErrorExtensions,
158
- }),
159
- ],
160
- };
161
- }
162
- if (Array.isArray(parsedResult.errors)) {
163
- return {
164
- ...parsedResult,
165
- errors: parsedResult.errors.map(({ message, ...options }) => (0, utils_1.createGraphQLError)(message, {
166
- ...options,
167
- extensions: {
168
- code: 'DOWNSTREAM_SERVICE_ERROR',
169
- ...(options.extensions || {}),
170
- },
171
- })),
172
- };
173
- }
174
- return parsedResult;
175
- }
176
- catch (e) {
177
- return {
178
- errors: [
179
- (0, utils_1.createGraphQLError)(`Unexpected response: ${JSON.stringify(result)}`, {
180
- extensions: upstreamErrorExtensions,
181
- originalError: e,
182
- }),
183
- ],
184
- };
185
- }
186
- }
187
- }
188
- else {
189
- return result;
190
- }
191
- })
192
- .catch((e) => {
193
- if (e.name === 'AggregateError') {
194
- return {
195
- errors: e.errors.map((e) => coerceFetchError(e, {
196
- signal,
197
- endpoint,
198
- upstreamErrorExtensions,
199
- })),
200
- };
201
- }
202
- return {
203
- errors: [
204
- coerceFetchError(e, {
205
- signal,
206
- endpoint,
207
- upstreamErrorExtensions,
208
- }),
209
- ],
210
- };
211
- })
212
- .resolve();
213
- };
214
- let executor = baseExecutor;
215
- if (options?.retry != null) {
216
- executor = function retryExecutor(request) {
217
- let result;
218
- let attempt = 0;
219
- function retryAttempt() {
220
- if (disposeCtrl?.signal.aborted) {
221
- return createResultForAbort(disposeCtrl.signal);
222
- }
223
- attempt++;
224
- if (attempt > options.retry) {
225
- if (result != null) {
226
- return result;
227
- }
228
- return {
229
- errors: [(0, utils_1.createGraphQLError)('No response returned from fetch')],
230
- };
231
- }
232
- return new value_or_promise_1.ValueOrPromise(() => baseExecutor(request))
233
- .then(res => {
234
- result = res;
235
- if (result?.errors?.length) {
236
- return retryAttempt();
237
- }
238
- return result;
239
- })
240
- .resolve();
241
- }
242
- return retryAttempt();
243
- };
244
- }
245
- if (!options?.disposable) {
246
- disposeCtrl = undefined;
247
- return executor;
248
- }
249
- disposeCtrl = new AbortController();
250
- Object.defineProperties(executor, {
251
- [Symbol.dispose]: {
252
- get() {
253
- return function dispose() {
254
- return disposeCtrl.abort(createAbortErrorReason());
255
- };
256
- },
257
- },
258
- [Symbol.asyncDispose]: {
259
- get() {
260
- return function asyncDispose() {
261
- return disposeCtrl.abort(createAbortErrorReason());
262
- };
263
- },
264
- },
265
- });
266
- return executor;
267
- }
268
- exports.buildHTTPExecutor = buildHTTPExecutor;
269
- function coerceFetchError(e, { signal, endpoint, upstreamErrorExtensions, }) {
270
- if (typeof e === 'string') {
271
- return (0, utils_1.createGraphQLError)(e, {
272
- extensions: upstreamErrorExtensions,
273
- });
274
- }
275
- else if (e.name === 'GraphQLError') {
276
- return e;
277
- }
278
- else if (e.name === 'TypeError' && e.message === 'fetch failed') {
279
- return (0, utils_1.createGraphQLError)(`fetch failed to ${endpoint}`, {
280
- extensions: upstreamErrorExtensions,
281
- originalError: e,
282
- });
283
- }
284
- else if (e.name === 'AbortError' && signal?.reason) {
285
- return createGraphQLErrorForAbort(signal, {
286
- extensions: upstreamErrorExtensions,
287
- });
288
- }
289
- else if (e.message) {
290
- return (0, utils_1.createGraphQLError)(e.message, {
291
- extensions: upstreamErrorExtensions,
292
- originalError: e,
293
- });
294
- }
295
- else {
296
- return (0, utils_1.createGraphQLError)('Unknown error', {
297
- extensions: upstreamErrorExtensions,
298
- originalError: e,
299
- });
300
- }
301
- }
302
- function createAbortErrorReason() {
303
- return new Error('Executor was disposed.');
304
- }
305
- function createGraphQLErrorForAbort(signal, extensions) {
306
- return (0, utils_1.createGraphQLError)('The operation was aborted. reason: ' + signal.reason, {
307
- extensions,
308
- });
309
- }
310
- function createResultForAbort(signal, extensions) {
311
- return {
312
- errors: [createGraphQLErrorForAbort(signal, extensions)],
313
- };
314
- }
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isGraphQLUpload = void 0;
4
- function isGraphQLUpload(upload) {
5
- return typeof upload.createReadStream === 'function';
6
- }
7
- exports.isGraphQLUpload = isGraphQLUpload;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isLiveQueryOperationDefinitionNode = void 0;
4
- const utils_1 = require("@graphql-tools/utils");
5
- exports.isLiveQueryOperationDefinitionNode = (0, utils_1.memoize1)(function isLiveQueryOperationDefinitionNode(node) {
6
- return (node.operation === 'query' &&
7
- node.directives?.some(directive => directive.name.value === 'live'));
8
- });
package/cjs/package.json DELETED
@@ -1 +0,0 @@
1
- {"type":"commonjs"}
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.prepareGETUrl = void 0;
4
- const graphql_1 = require("graphql");
5
- function prepareGETUrl({ baseUrl = '', query, variables, operationName, extensions, }) {
6
- const dummyHostname = 'https://dummyhostname.com';
7
- const validUrl = baseUrl.startsWith('http')
8
- ? baseUrl
9
- : baseUrl?.startsWith('/')
10
- ? `${dummyHostname}${baseUrl}`
11
- : `${dummyHostname}/${baseUrl}`;
12
- const urlObj = new URL(validUrl);
13
- urlObj.searchParams.set('query', (0, graphql_1.stripIgnoredCharacters)(query));
14
- if (variables && Object.keys(variables).length > 0) {
15
- urlObj.searchParams.set('variables', JSON.stringify(variables));
16
- }
17
- if (operationName) {
18
- urlObj.searchParams.set('operationName', operationName);
19
- }
20
- if (extensions) {
21
- urlObj.searchParams.set('extensions', JSON.stringify(extensions));
22
- }
23
- const finalUrl = urlObj.toString().replace(dummyHostname, '');
24
- return finalUrl;
25
- }
26
- exports.prepareGETUrl = prepareGETUrl;