UNPKG

2.13 kBTypeScriptView Raw
1import type { TypedDocumentNode } from '@graphql-typed-document-node/core';
2import type { BatchRequestDocument, BatchRequestsOptions, BatchResult } from '../functions/batchRequests.js';
3import type { RequestDocument, RequestOptions, VariablesAndRequestHeadersArgs } from '../helpers/types.js';
4import { type GraphQLClientResponse, type RawRequestOptions, type RequestConfig, type Variables } from '../helpers/types.js';
5/**
6 * GraphQL Client.
7 */
8export declare class GraphQLClient {
9 private url;
10 readonly requestConfig: RequestConfig;
11 constructor(url: string, requestConfig?: RequestConfig);
12 /**
13 * Send a GraphQL query to the server.
14 */
15 rawRequest: RawRequestMethod;
16 /**
17 * Send a GraphQL document to the server.
18 */
19 request<T, V extends Variables = Variables>(document: RequestDocument | TypedDocumentNode<T, V>, ...variablesAndRequestHeaders: VariablesAndRequestHeadersArgs<V>): Promise<T>;
20 request<T, V extends Variables = Variables>(options: RequestOptions<V, T>): Promise<T>;
21 /**
22 * Send GraphQL documents in batch to the server.
23 */
24 batchRequests<$BatchResult extends BatchResult, $Variables extends Variables = Variables>(documents: BatchRequestDocument<$Variables>[], requestHeaders?: HeadersInit): Promise<$BatchResult>;
25 batchRequests<$BatchResult extends BatchResult, $Variables extends Variables = Variables>(options: BatchRequestsOptions<$Variables>): Promise<$BatchResult>;
26 setHeaders(headers: HeadersInit): this;
27 /**
28 * Attach a header to the client. All subsequent requests will have this header.
29 */
30 setHeader(key: string, value: string): this;
31 /**
32 * Change the client endpoint. All subsequent requests will send to this endpoint.
33 */
34 setEndpoint(value: string): this;
35}
36interface RawRequestMethod {
37 <T, V extends Variables = Variables>(query: string, variables?: V, requestHeaders?: HeadersInit): Promise<GraphQLClientResponse<T>>;
38 <T, V extends Variables = Variables>(options: RawRequestOptions<V>): Promise<GraphQLClientResponse<T>>;
39}
40export {};
41//# sourceMappingURL=GraphQLClient.d.ts.map
\No newline at end of file