import type { DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; import type { GraphQLError } from 'graphql'; import type { DocumentNode } from 'graphql'; import type { MaybeLazy, MaybePromise, RemoveIndex } from '../../lib/prelude.js'; import type { ClientError } from '../classes/ClientError.js'; export type Fetch = typeof fetch; /** * 'None' will throw whenever the response contains errors * * 'Ignore' will ignore incoming errors and resolve like no errors occurred * * 'All' will return both the errors and data */ export type ErrorPolicy = 'none' | 'ignore' | 'all'; export interface JsonSerializer { stringify: (obj: any) => string; parse: (obj: string) => unknown; } export interface AdditionalRequestOptions { jsonSerializer?: JsonSerializer; /** * Decide how to handle GraphQLErrors in response */ errorPolicy?: ErrorPolicy; } export interface FetchOptions extends RequestInit, AdditionalRequestOptions { } export type { GraphQLError }; export type Variables = object; export type BatchVariables = (Variables | undefined)[]; export interface GraphQLResponse { data?: T; errors?: GraphQLError[]; extensions?: unknown; status: number; headers: Headers; /** * The response body text. Useful for debugging non-GraphQL responses * (e.g., 401/403 errors that return plain JSON instead of GraphQL). */ body: string; [key: string]: unknown; } export interface GraphQLRequestContext { query: string | string[]; variables?: V; } export type RequestDocument = string | String | DocumentNode; /** * TypedDocumentString is generated by \@graphql-codegen with `documentMode: 'string'`. * It's a boxed String with type metadata for result and variables types. * @see https://github.com/graffle-js/graffle/issues/1467 */ export type TypedDocumentString<$Result, $Variables> = String & DocumentTypeDecoration<$Result, $Variables>; export interface GraphQLClientResponse { status: number; headers: Headers; /** * The response body text. Useful for debugging non-GraphQL responses * (e.g., 401/403 errors that return plain JSON instead of GraphQL). */ body: string; data: Data; extensions?: unknown; errors?: GraphQLError[]; } export type HTTPMethodInput = 'GET' | 'POST' | 'get' | 'post'; export interface RequestConfig extends Omit, AdditionalRequestOptions { fetch?: Fetch; method?: HTTPMethodInput; headers?: MaybeLazy; requestMiddleware?: RequestMiddleware; responseMiddleware?: ResponseMiddleware; jsonSerializer?: JsonSerializer; excludeOperationName?: boolean; } export type RawRequestOptions = { query: string; requestHeaders?: HeadersInit; signal?: RequestInit['signal']; } & (V extends Record ? { variables?: V; } : keyof RemoveIndex extends never ? { variables?: V; } : { variables: V; }); export type RequestOptions = { document: RequestDocument | TypedDocumentNode | TypedDocumentString; requestHeaders?: HeadersInit; signal?: RequestInit['signal']; } & (V extends Record ? { variables?: V; } : keyof RemoveIndex extends never ? { variables?: V; } : { variables: V; }); export type ResponseMiddleware = (response: GraphQLClientResponse | ClientError | Error, request: RequestInitExtended) => MaybePromise; export type RequestMiddleware = (request: RequestInitExtended) => RequestInitExtended | Promise; export type RequestInitExtended = RequestInit & { url: string; operationName?: string; variables?: V; }; export type VariablesAndRequestHeadersArgs = V extends Record ? [variables?: V, requestHeaders?: HeadersInit] : keyof RemoveIndex extends never ? [variables?: V, requestHeaders?: HeadersInit] : [variables: V, requestHeaders?: HeadersInit]; //# sourceMappingURL=types.d.ts.map