Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@graphql-tools/executor-http

Package Overview
Dependencies
Maintainers
4
Versions
483
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-tools/executor-http - npm Package Compare versions

Comparing version 1.1.10-alpha-3290cdd564ea51739556154472c01ac921f2f91d to 1.1.10-alpha-332298306efaee973970682c85d492df34c27619

16

CHANGELOG.md
# @graphql-tools/executor-http
## 1.1.10-alpha-3290cdd564ea51739556154472c01ac921f2f91d
## 1.1.10-alpha-332298306efaee973970682c85d492df34c27619
### Patch Changes
- [#98](https://github.com/graphql-hive/gateway/pull/98) [`3290cdd`](https://github.com/graphql-hive/gateway/commit/3290cdd564ea51739556154472c01ac921f2f91d) Thanks [@ardatan](https://github.com/ardatan)! - Bun support by using native Bun API whenever possible
- [#164](https://github.com/graphql-hive/gateway/pull/164) [`310613d`](https://github.com/graphql-hive/gateway/commit/310613d68d1df3e2bceafbd0730084a4c83527bf) Thanks [@ardatan](https://github.com/ardatan)! - dependencies updates:
- Updated dependency [`@graphql-tools/utils@^10.6.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.6.0) (from `^10.5.6`, in `dependencies`)
- [#180](https://github.com/graphql-hive/gateway/pull/180) [`9438e21`](https://github.com/graphql-hive/gateway/commit/9438e21982ed5c6fb18cb678b275046595ae00f5) Thanks [@ardatan](https://github.com/ardatan)! - dependencies updates:
- Added dependency [`@whatwg-node/disposablestack@^0.0.5` ↗︎](https://www.npmjs.com/package/@whatwg-node/disposablestack/v/0.0.5) (to `dependencies`)
- [#180](https://github.com/graphql-hive/gateway/pull/180) [`9438e21`](https://github.com/graphql-hive/gateway/commit/9438e21982ed5c6fb18cb678b275046595ae00f5) Thanks [@ardatan](https://github.com/ardatan)! - Use new explicit resource management internally
- [#199](https://github.com/graphql-hive/gateway/pull/199) [`b534288`](https://github.com/graphql-hive/gateway/commit/b5342885f8ac1197d70cbf45266c83b720b4f85a) Thanks [@ardatan](https://github.com/ardatan)! - Logs are now easier to read, bigger results not do not create bigger outputs but instead they are all logged in a single line
- [#98](https://github.com/graphql-hive/gateway/pull/98) [`697308d`](https://github.com/graphql-hive/gateway/commit/697308df3b2dd96f28dc65a5f5361a911077e022) Thanks [@ardatan](https://github.com/ardatan)! - Bun support by using native Bun API whenever possible
## 1.1.9

@@ -10,0 +22,0 @@

38

dist/index.d.ts

@@ -1,2 +0,2 @@

import { ExecutionRequest, DisposableSyncExecutor, SyncExecutor, DisposableAsyncExecutor, AsyncExecutor } from '@graphql-tools/utils';
import { ExecutionRequest, DisposableSyncExecutor, DisposableAsyncExecutor } from '@graphql-tools/utils';
import { OperationDefinitionNode, GraphQLResolveInfo, DocumentNode } from 'graphql';

@@ -60,3 +60,3 @@

* Enable [Explicit Resource Management](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management)
* @default false
* @deprecated The executors are always disposable, and this option will be removed in the next major version, there is no need to have a flag for this.
*/

@@ -66,43 +66,13 @@ disposable?: boolean;

type HeadersConfig = Record<string, string>;
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch' | 'disposable'> & {
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'> & {
fetch: SyncFetchFn;
disposable: true;
}): DisposableSyncExecutor<any, HTTPExecutorOptions>;
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch' | 'disposable'> & {
fetch: SyncFetchFn;
disposable: false;
}): SyncExecutor<any, HTTPExecutorOptions>;
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'> & {
fetch: SyncFetchFn;
}): SyncExecutor<any, HTTPExecutorOptions>;
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch' | 'disposable'> & {
fetch: AsyncFetchFn;
disposable: true;
}): DisposableAsyncExecutor<any, HTTPExecutorOptions>;
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch' | 'disposable'> & {
fetch: AsyncFetchFn;
disposable: false;
}): AsyncExecutor<any, HTTPExecutorOptions>;
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'> & {
fetch: AsyncFetchFn;
}): AsyncExecutor<any, HTTPExecutorOptions>;
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch' | 'disposable'> & {
fetch: RegularFetchFn;
disposable: true;
}): DisposableAsyncExecutor<any, HTTPExecutorOptions>;
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch' | 'disposable'> & {
fetch: RegularFetchFn;
disposable: false;
}): AsyncExecutor<any, HTTPExecutorOptions>;
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'> & {
fetch: RegularFetchFn;
}): AsyncExecutor<any, HTTPExecutorOptions>;
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch' | 'disposable'> & {
disposable: true;
}): DisposableAsyncExecutor<any, HTTPExecutorOptions>;
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch' | 'disposable'> & {
disposable: false;
}): AsyncExecutor<any, HTTPExecutorOptions>;
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'>): AsyncExecutor<any, HTTPExecutorOptions>;
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'>): DisposableAsyncExecutor<any, HTTPExecutorOptions>;
export { type AsyncFetchFn, type AsyncImportFn, type FetchFn, type HTTPExecutorOptions, type HeadersConfig, type RegularFetchFn, type SyncFetchFn, type SyncImportFn, type SyncResponse, buildHTTPExecutor, isLiveQueryOperationDefinitionNode };

@@ -1,2 +0,3 @@

import { isAsyncIterable, isPromise, inspect, mapAsyncIterator, mergeIncrementalResult, memoize1, getOperationASTFromRequest, createGraphQLError } from '@graphql-tools/utils';
import { isAsyncIterable, isPromise, fakePromise, createGraphQLError, inspect, mapAsyncIterator, mergeIncrementalResult, memoize1, getOperationASTFromRequest, mapMaybePromise } from '@graphql-tools/utils';
import { DisposableSymbols } from '@whatwg-node/disposablestack';
import { File, FormData, TextDecoder, fetch } from '@whatwg-node/fetch';

@@ -59,3 +60,3 @@ import { ValueOrPromise } from 'value-or-promise';

);
form.append("map", JSON.stringify(map, null, 2));
form.append("map", JSON.stringify(map));
function handleUpload(upload, i) {

@@ -74,3 +75,3 @@ const indexStr = i.toString();

const chunks = [];
return Promise.resolve().then(async () => {
return fakePromise(void 0).then(async () => {
for await (const chunk of stream) {

@@ -93,7 +94,14 @@ if (chunk) {

}
return ValueOrPromise.all(
uploads.map(
(upload, i) => new ValueOrPromise(() => handleUpload(upload, i))
)
).then(() => form).resolve();
const jobs = [];
for (const i in uploads) {
const upload = uploads[i];
const job = handleUpload(upload, Number(i));
if (isPromise(job)) {
jobs.push(job);
}
}
if (jobs.length > 0) {
return Promise.all(jobs).then(() => form);
}
return form;
}

@@ -114,2 +122,16 @@ function isBlob(obj) {

function createAbortErrorReason() {
return new Error("Executor was disposed.");
}
function createGraphQLErrorForAbort(reason, extensions) {
return createGraphQLError("The operation was aborted. reason: " + reason, {
extensions
});
}
function createResultForAbort(reason, extensions) {
return {
errors: [createGraphQLErrorForAbort(reason, extensions)]
};
}
const DELIM = "\n\n";

@@ -119,3 +141,3 @@ function isReadableStream(value) {

}
function handleEventStreamResponse(response) {
function handleEventStreamResponse(signal, response) {
const body = response.body;

@@ -136,2 +158,6 @@ if (!isReadableStream(body)) {

async function pump() {
if (signal.aborted) {
await push(createResultForAbort(signal));
return stop();
}
if (!body?.locked) {

@@ -236,8 +262,25 @@ return stop();

function createSignalWrapper(signal) {
const listeners = /* @__PURE__ */ new Set();
signal.onabort = (event) => {
for (const listener of listeners) {
listener(event);
}
};
return Object.assign(signal, {
addEventListener(_type, listener) {
listeners.add(listener);
},
removeEventListener(_type, listener) {
listeners.delete(listener);
}
});
}
function buildHTTPExecutor(options) {
const printFn = options?.print ?? defaultPrintFn;
let disposeCtrl;
const disposeCtrl = new AbortController();
const sharedSignal = createSignalWrapper(disposeCtrl.signal);
const baseExecutor = (request) => {
if (disposeCtrl?.signal.aborted) {
return createResultForAbort(disposeCtrl.signal);
if (sharedSignal.aborted) {
return createResultForAbort(sharedSignal.reason);
}

@@ -272,18 +315,8 @@ const fetchFn = request.extensions?.fetch ?? options?.fetch ?? fetch;

const query = printFn(request.document);
let signal = disposeCtrl?.signal;
let clearTimeoutFn = () => {
};
let signal = sharedSignal;
if (options?.timeout) {
const timeoutCtrl = new AbortController();
signal = timeoutCtrl.signal;
disposeCtrl?.signal.addEventListener("abort", clearTimeoutFn);
const timeoutId = setTimeout(() => {
if (!timeoutCtrl.signal.aborted) {
timeoutCtrl.abort("timeout");
}
disposeCtrl?.signal.removeEventListener("abort", clearTimeoutFn);
}, options.timeout);
clearTimeoutFn = () => {
clearTimeout(timeoutId);
};
signal = AbortSignal.any([
sharedSignal,
AbortSignal.timeout(options.timeout)
]);
}

@@ -325,28 +358,29 @@ const upstreamErrorExtensions = {

upstreamErrorExtensions.request.body = body;
return new ValueOrPromise(
() => createFormDataFromVariables(body, {
return mapMaybePromise(
createFormDataFromVariables(body, {
File: options?.File,
FormData: options?.FormData
})
).then((body2) => {
if (typeof body2 === "string" && !headers["content-type"]) {
upstreamErrorExtensions.request.body = body2;
headers["content-type"] = "application/json";
}),
(body2) => {
if (typeof body2 === "string" && !headers["content-type"]) {
upstreamErrorExtensions.request.body = body2;
headers["content-type"] = "application/json";
}
const fetchOptions = {
method: "POST",
body: body2,
headers,
signal
};
if (options?.credentials != null) {
fetchOptions.credentials = options.credentials;
}
return fetchFn(
endpoint,
fetchOptions,
request.context,
request.info
);
}
const fetchOptions = {
method: "POST",
body: body2,
headers,
signal
};
if (options?.credentials != null) {
fetchOptions.credentials = options.credentials;
}
return fetchFn(
endpoint,
fetchOptions,
request.context,
request.info
);
}).resolve();
);
}

@@ -362,3 +396,2 @@ }

});
clearTimeoutFn();
if (options?.retry != null && !fetchResult.status.toString().startsWith("2")) {

@@ -371,3 +404,3 @@ throw new Error(

if (contentType?.includes("text/event-stream")) {
return handleEventStreamResponse(fetchResult);
return handleEventStreamResponse(signal, fetchResult);
} else if (contentType?.includes("multipart/mixed")) {

@@ -460,4 +493,4 @@ return handleMultipartMixedResponse(fetchResult);

function retryAttempt() {
if (disposeCtrl?.signal.aborted) {
return createResultForAbort(disposeCtrl.signal);
if (sharedSignal.aborted) {
return createResultForAbort(sharedSignal.reason);
}

@@ -473,3 +506,3 @@ attempt++;

}
return new ValueOrPromise(() => baseExecutor(request)).then((res) => {
return mapMaybePromise(baseExecutor(request), (res) => {
result = res;

@@ -480,3 +513,3 @@ if (result?.errors?.length) {

return result;
}).resolve();
});
}

@@ -486,9 +519,4 @@ return retryAttempt();

}
if (!options?.disposable) {
disposeCtrl = void 0;
return executor;
}
disposeCtrl = new AbortController();
Object.defineProperties(executor, {
[Symbol.dispose]: {
[DisposableSymbols.dispose]: {
get() {

@@ -500,3 +528,3 @@ return function dispose() {

},
[Symbol.asyncDispose]: {
[DisposableSymbols.asyncDispose]: {
get() {

@@ -527,4 +555,4 @@ return function asyncDispose() {

});
} else if (e.name === "AbortError" && signal?.reason) {
return createGraphQLErrorForAbort(signal, {
} else if (e.name === "AbortError" && signal.reason) {
return createGraphQLErrorForAbort(signal.reason, {
extensions: upstreamErrorExtensions

@@ -544,19 +572,3 @@ });

}
function createAbortErrorReason() {
return new Error("Executor was disposed.");
}
function createGraphQLErrorForAbort(signal, extensions) {
return createGraphQLError(
"The operation was aborted. reason: " + signal.reason,
{
extensions
}
);
}
function createResultForAbort(signal, extensions) {
return {
errors: [createGraphQLErrorForAbort(signal, extensions)]
};
}
export { buildHTTPExecutor, isLiveQueryOperationDefinitionNode };
{
"name": "@graphql-tools/executor-http",
"version": "1.1.10-alpha-3290cdd564ea51739556154472c01ac921f2f91d",
"version": "1.1.10-alpha-332298306efaee973970682c85d492df34c27619",
"type": "module",

@@ -42,4 +42,5 @@ "description": "A set of utils for faster development of GraphQL tools",

"dependencies": {
"@graphql-tools/utils": "^10.5.6",
"@graphql-tools/utils": "^10.6.0",
"@repeaterjs/repeater": "^3.0.4",
"@whatwg-node/disposablestack": "^0.0.5",
"@whatwg-node/fetch": "^0.10.0",

@@ -46,0 +47,0 @@ "extract-files": "^11.0.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc