UNPKG

3.43 kBTypeScriptView Raw
1import type { TypedDocumentNode } from '@graphql-typed-document-node/core';
2import type { GraphQLError } from 'graphql';
3import type { DocumentNode } from 'graphql';
4import type { MaybeLazy, MaybePromise, RemoveIndex } from '../../lib/prelude.js';
5import type { ClientError } from '../classes/ClientError.js';
6export type Fetch = typeof fetch;
7/**
8 * 'None' will throw whenever the response contains errors
9 *
10 * 'Ignore' will ignore incoming errors and resolve like no errors occurred
11 *
12 * 'All' will return both the errors and data
13 */
14export type ErrorPolicy = 'none' | 'ignore' | 'all';
15export interface JsonSerializer {
16 stringify: (obj: any) => string;
17 parse: (obj: string) => unknown;
18}
19export interface AdditionalRequestOptions {
20 jsonSerializer?: JsonSerializer;
21 /**
22 * Decide how to handle GraphQLErrors in response
23 */
24 errorPolicy?: ErrorPolicy;
25}
26export interface FetchOptions extends RequestInit, AdditionalRequestOptions {
27}
28export type { GraphQLError };
29export type Variables = object;
30export type BatchVariables = (Variables | undefined)[];
31export interface GraphQLResponse<T = unknown> {
32 data?: T;
33 errors?: GraphQLError[];
34 extensions?: unknown;
35 status: number;
36 [key: string]: unknown;
37}
38export interface GraphQLRequestContext<V extends Variables = Variables> {
39 query: string | string[];
40 variables?: V;
41}
42export type RequestDocument = string | DocumentNode;
43export interface GraphQLClientResponse<Data> {
44 status: number;
45 headers: Headers;
46 data: Data;
47 extensions?: unknown;
48 errors?: GraphQLError[];
49}
50export type HTTPMethodInput = 'GET' | 'POST' | 'get' | 'post';
51export interface RequestConfig extends Omit<RequestInit, 'headers' | 'method'>, AdditionalRequestOptions {
52 fetch?: Fetch;
53 method?: HTTPMethodInput;
54 headers?: MaybeLazy<HeadersInit>;
55 requestMiddleware?: RequestMiddleware;
56 responseMiddleware?: ResponseMiddleware;
57 jsonSerializer?: JsonSerializer;
58 excludeOperationName?: boolean;
59}
60export type RawRequestOptions<V extends Variables = Variables> = {
61 query: string;
62 requestHeaders?: HeadersInit;
63 signal?: RequestInit['signal'];
64} & (V extends Record<any, never> ? {
65 variables?: V;
66} : keyof RemoveIndex<V> extends never ? {
67 variables?: V;
68} : {
69 variables: V;
70});
71export type RequestOptions<V extends Variables = Variables, T = unknown> = {
72 document: RequestDocument | TypedDocumentNode<T, V>;
73 requestHeaders?: HeadersInit;
74 signal?: RequestInit['signal'];
75} & (V extends Record<any, never> ? {
76 variables?: V;
77} : keyof RemoveIndex<V> extends never ? {
78 variables?: V;
79} : {
80 variables: V;
81});
82export type ResponseMiddleware = (response: GraphQLClientResponse<unknown> | ClientError | Error, request: RequestInitExtended) => MaybePromise<void>;
83export type RequestMiddleware<V extends Variables = Variables> = (request: RequestInitExtended<V>) => RequestInitExtended | Promise<RequestInitExtended>;
84export type RequestInitExtended<V extends Variables = Variables> = RequestInit & {
85 url: string;
86 operationName?: string;
87 variables?: V;
88};
89export type VariablesAndRequestHeadersArgs<V extends Variables> = V extends Record<any, never> ? [variables?: V, requestHeaders?: HeadersInit] : keyof RemoveIndex<V> extends never ? [variables?: V, requestHeaders?: HeadersInit] : [variables: V, requestHeaders?: HeadersInit];
90//# sourceMappingURL=types.d.ts.map
\No newline at end of file