-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
153 lines (132 loc) · 4.13 KB
/
types.ts
File metadata and controls
153 lines (132 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import type { CommonConnectionConfig, CommonOptions } from "@probitas/client";
import type {
GraphqlResponse,
GraphqlResponseError,
GraphqlResponseFailure,
GraphqlResponseSuccess,
} from "./response.ts";
/**
* GraphQL error item as per GraphQL specification.
* @see https://spec.graphql.org/October2021/#sec-Errors.Error-Result-Format
*/
export interface GraphqlErrorItem {
/** Error message */
readonly message: string;
/** Location(s) in the GraphQL document where the error occurred */
readonly locations: readonly { line: number; column: number }[] | null;
/** Path to the field that caused the error */
readonly path: readonly (string | number)[] | null;
/** Additional error metadata */
readonly extensions: Record<string, unknown> | null;
}
export type {
GraphqlResponse,
GraphqlResponseError,
GraphqlResponseFailure,
GraphqlResponseSuccess,
};
/**
* Options for individual GraphQL requests.
*/
export interface GraphqlOptions extends CommonOptions {
/** Additional request headers */
readonly headers?: HeadersInit;
/** Operation name (for documents with multiple operations) */
readonly operationName?: string;
/**
* Whether to throw GraphqlError when response contains errors or request fails.
* @default false (inherited from client config if not specified)
*/
readonly throwOnError?: boolean;
}
/**
* GraphQL connection configuration.
*
* Extends CommonConnectionConfig with GraphQL-specific options.
*/
export interface GraphqlConnectionConfig extends CommonConnectionConfig {
/**
* Protocol to use.
* @default "http"
*/
readonly protocol?: "http" | "https";
/**
* GraphQL endpoint path.
* @default "/graphql"
*/
readonly path?: string;
}
/**
* GraphQL client configuration.
*/
export interface GraphqlClientConfig extends CommonOptions {
/**
* GraphQL endpoint URL.
*
* Can be a URL string or a connection configuration object.
*
* @example String URL
* ```ts
* import type { GraphqlClientConfig } from "@probitas/client-graphql";
* const config: GraphqlClientConfig = { url: "http://localhost:4000/graphql" };
* ```
*
* @example Connection config object
* ```ts
* import type { GraphqlClientConfig } from "@probitas/client-graphql";
* const config: GraphqlClientConfig = {
* url: { host: "api.example.com", port: 443, protocol: "https" },
* };
* ```
*/
readonly url: string | GraphqlConnectionConfig;
/** Default headers for all requests */
readonly headers?: HeadersInit;
/** WebSocket endpoint URL (for subscriptions) */
readonly wsEndpoint?: string;
/** Custom fetch implementation (for testing/mocking) */
readonly fetch?: typeof fetch;
/**
* Whether to throw GraphqlError when response contains errors or request fails.
* Can be overridden per-request via GraphqlOptions.
* @default false
*/
readonly throwOnError?: boolean;
}
/**
* GraphQL client interface.
*/
export interface GraphqlClient extends AsyncDisposable {
/** Client configuration */
readonly config: GraphqlClientConfig;
/** Execute a GraphQL query */
// deno-lint-ignore no-explicit-any
query<TData = any, TVariables = Record<string, any>>(
query: string,
variables?: TVariables,
options?: GraphqlOptions,
): Promise<GraphqlResponse<TData>>;
/** Execute a GraphQL mutation */
// deno-lint-ignore no-explicit-any
mutation<TData = any, TVariables = Record<string, any>>(
mutation: string,
variables?: TVariables,
options?: GraphqlOptions,
): Promise<GraphqlResponse<TData>>;
/** Execute a GraphQL document (query or mutation) */
// deno-lint-ignore no-explicit-any
execute<TData = any, TVariables = Record<string, any>>(
document: string,
variables?: TVariables,
options?: GraphqlOptions,
): Promise<GraphqlResponse<TData>>;
/** Subscribe to a GraphQL subscription via WebSocket */
// deno-lint-ignore no-explicit-any
subscribe<TData = any, TVariables = Record<string, any>>(
document: string,
variables?: TVariables,
options?: GraphqlOptions,
): AsyncIterable<GraphqlResponse<TData>>;
/** Close the client and release resources */
close(): Promise<void>;
}