@graphql-hive/core
Version:
58 lines • 2.21 kB
TypeScript
import asyncRetry from 'async-retry';
import { fetch, URL } from '@whatwg-node/fetch';
import type { Logger } from './types.js';
interface SharedConfig {
headers: Record<string, string>;
/**
* timeout in milliseconds (for each single fetch call)
* @default 20_000
*/
timeout?: number;
/** Retry configuration. Set to `false` for having no retries. */
retry?: RetryOptions | false;
/** custom fetch implementation. */
fetchImplementation?: typeof fetch;
/** Logger for HTTP info and request errors. Uses `console` by default. */
logger?: Logger;
/**
* Function for determining whether the request response is okay.
* You can override it if you want to accept other status codes as well.
* @default {response => response.ok}
**/
isRequestOk?: ResponseAssertFunction;
}
/**
* Return a string that contains the reason on why the request should be retried.
*/
type ResponseAssertFunction = (response: Response) => boolean;
type RetryOptions = Parameters<typeof asyncRetry>[1];
declare function get(endpoint: string, config: SharedConfig): Promise<Response>;
declare function post(endpoint: string, data: string | Buffer, config: SharedConfig): Promise<Response>;
export declare const http: {
get: typeof get;
post: typeof post;
};
export declare function makeFetchCall(endpoint: URL | string, config: {
body?: string | Buffer;
method: 'GET' | 'POST';
headers: Record<string, string>;
/**
* timeout in milliseconds (for each single fetch call)
* @default 20_000
*/
timeout?: number;
/** Retry configuration. Set to `false` for having no retries. */
retry?: RetryOptions | false;
/** custom fetch implementation. */
fetchImplementation?: typeof fetch;
/** Logger for HTTP info and request errors. Uses `console` by default. */
logger?: Logger;
/**
* Function for determining whether the request response is okay.
* You can override it if you want to accept other status codes as well.
* @default {response => response.ok}
**/
isRequestOk?: ResponseAssertFunction;
}): Promise<Response>;
export { URL };
//# sourceMappingURL=http-client.d.ts.map