@schema-hub/zod-graphql-client 0.0.14 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +25 -7
- package/readme.md +127 -45
- package/sbom.cdx.json +101 -0
- package/zod-graphql-client/client.d.ts +10 -24
- package/zod-graphql-client/client.d.ts.map +1 -1
- package/zod-graphql-client/client.js +111 -93
- package/zod-graphql-client/client.js.map +1 -1
- package/zod-graphql-client/define-variables.d.ts +28 -0
- package/zod-graphql-client/define-variables.d.ts.map +1 -0
- package/zod-graphql-client/define-variables.js +11 -0
- package/zod-graphql-client/define-variables.js.map +1 -0
- package/zod-graphql-client/entry-point.d.ts +12 -4
- package/zod-graphql-client/entry-point.d.ts.map +1 -1
- package/zod-graphql-client/entry-point.js +4 -1
- package/zod-graphql-client/entry-point.js.map +1 -1
- package/zod-graphql-client/graphql-error.d.ts +12 -0
- package/zod-graphql-client/graphql-error.d.ts.map +1 -0
- package/zod-graphql-client/graphql-error.js +2 -36
- package/zod-graphql-client/graphql-error.js.map +1 -1
- package/zod-graphql-client/graphql-response.js +3 -3
- package/zod-graphql-client/graphql-response.js.map +1 -1
- package/zod-graphql-client/infer-graphql-type.d.ts +2 -0
- package/zod-graphql-client/infer-graphql-type.d.ts.map +1 -0
- package/zod-graphql-client/infer-graphql-type.js +67 -0
- package/zod-graphql-client/infer-graphql-type.js.map +1 -0
- package/zod-graphql-client/operation-error.d.ts +7 -7
- package/zod-graphql-client/operation-error.d.ts.map +1 -1
- package/zod-graphql-client/operation-error.js +2 -1
- package/zod-graphql-client/operation-error.js.map +1 -1
- package/zod-graphql-client/operation-handle.d.ts +13 -0
- package/zod-graphql-client/operation-handle.d.ts.map +1 -0
- package/zod-graphql-client/operation-handle.js +1 -0
- package/zod-graphql-client/operation-handle.js.map +1 -0
- package/zod-graphql-client/operation-payload.d.ts +24 -0
- package/zod-graphql-client/operation-payload.d.ts.map +1 -0
- package/zod-graphql-client/operation-payload.js +70 -0
- package/zod-graphql-client/operation-payload.js.map +1 -0
- package/zod-graphql-client/operation-result.d.ts +1 -1
- package/zod-graphql-client/persisted-query.d.ts +9 -0
- package/zod-graphql-client/persisted-query.d.ts.map +1 -0
- package/zod-graphql-client/persisted-query.js +50 -0
- package/zod-graphql-client/persisted-query.js.map +1 -0
- package/zod-graphql-client/variable-entry.d.ts +11 -0
- package/zod-graphql-client/variable-entry.d.ts.map +1 -0
- package/zod-graphql-client/variable-entry.js +2 -0
- package/zod-graphql-client/variable-entry.js.map +1 -0
- package/zod-graphql-client/variables.d.ts +0 -9
- package/zod-graphql-client/variables.d.ts.map +0 -1
- package/zod-graphql-client/variables.js +0 -15
- package/zod-graphql-client/variables.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Mathias Schreck <schreck.mathias@gmail.com>",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"@schema-hub/zod-error-formatter": "0.0.
|
|
5
|
-
"@schema-hub/zod-graphql-query-builder": "0.0.
|
|
6
|
-
"ky": "
|
|
4
|
+
"@schema-hub/zod-error-formatter": "0.0.12",
|
|
5
|
+
"@schema-hub/zod-graphql-query-builder": "0.0.14",
|
|
6
|
+
"ky": "2.0.2"
|
|
7
7
|
},
|
|
8
8
|
"description": "A lightweight and type-safe zod-based GraphQL client",
|
|
9
9
|
"engines": {
|
|
10
|
-
"node": "^
|
|
10
|
+
"node": "^24 || ^26"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./zod-graphql-client/entry-point.js",
|
|
15
|
+
"types": "./zod-graphql-client/entry-point.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"./zod-graphql-client/client.js": {
|
|
18
|
+
"import": "./zod-graphql-client/client.js",
|
|
19
|
+
"types": "./zod-graphql-client/client.d.ts"
|
|
20
|
+
},
|
|
21
|
+
"./zod-graphql-client/operation-payload.js": {
|
|
22
|
+
"import": "./zod-graphql-client/operation-payload.js",
|
|
23
|
+
"types": "./zod-graphql-client/operation-payload.d.ts"
|
|
24
|
+
}
|
|
11
25
|
},
|
|
12
26
|
"keywords": [
|
|
13
27
|
"graphql",
|
|
@@ -18,7 +32,6 @@
|
|
|
18
32
|
"zod-graphql"
|
|
19
33
|
],
|
|
20
34
|
"license": "MIT",
|
|
21
|
-
"main": "zod-graphql-client/entry-point.js",
|
|
22
35
|
"name": "@schema-hub/zod-graphql-client",
|
|
23
36
|
"peerDependencies": {
|
|
24
37
|
"zod": "^4.0.5"
|
|
@@ -27,7 +40,12 @@
|
|
|
27
40
|
"type": "git",
|
|
28
41
|
"url": "git+ssh://git@github.com/enormora/schema-hub.git"
|
|
29
42
|
},
|
|
43
|
+
"sideEffects": [
|
|
44
|
+
"./zod-graphql-client/graphql-error.js",
|
|
45
|
+
"./zod-graphql-client/graphql-response.js",
|
|
46
|
+
"./zod-graphql-client/infer-graphql-type.js",
|
|
47
|
+
"./zod-graphql-client/persisted-query.js"
|
|
48
|
+
],
|
|
30
49
|
"type": "module",
|
|
31
|
-
"
|
|
32
|
-
"version": "0.0.14"
|
|
50
|
+
"version": "0.0.15"
|
|
33
51
|
}
|
package/readme.md
CHANGED
|
@@ -59,77 +59,127 @@ You can further customize the client by providing additional options:
|
|
|
59
59
|
- `headers` (optional): A key-value map of additional headers that should be sent with every request. This can be useful for passing authentication tokens or other metadata to the server.
|
|
60
60
|
- `timeout` (optional): The request timeout in milliseconds. This determines how long the client will wait for a response before considering the request failed. If not specified, a default timeout of 10 seconds (10,000 milliseconds) will be used.
|
|
61
61
|
- `fetch` (optional): Allows you to inject a custom `fetch` function instead of using the global `fetch`. This can be useful in environments where the global `fetch` function is not available, or if you need to customize the behavior of the HTTP requests.
|
|
62
|
+
- `persistedQueries` (optional): Enables [Automatic Persisted Queries (APQ)](#automatic-persisted-queries-apq) for every operation. Defaults to `false`.
|
|
62
63
|
|
|
63
64
|
### Sending a Query
|
|
64
65
|
|
|
66
|
+
Bare-schema queries with no variables can be sent directly:
|
|
67
|
+
|
|
65
68
|
```typescript
|
|
66
|
-
import { createGraphqlClient
|
|
69
|
+
import { createGraphqlClient } from '@schema-hub/zod-graphql-client';
|
|
67
70
|
import { z } from 'zod';
|
|
68
71
|
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
const schema = z.object({ foo: z.string() }).strict();
|
|
73
|
+
const client = createGraphqlClient({ endpoint: 'https://example.com/graphql' });
|
|
74
|
+
const result = await client.query(schema);
|
|
75
|
+
|
|
76
|
+
console.log(result);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
For queries that take variables — or for queries that need a named operation — use `defineVariables` and `defineQuery` to bundle the schema, variable definitions, and operation name into a single typed operation handle. Variable values passed to `client.query` are then type-checked against the variable definitions:
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import {
|
|
83
|
+
createGraphqlClient,
|
|
84
|
+
defineQuery,
|
|
85
|
+
defineVariables,
|
|
86
|
+
graphqlFieldOptions
|
|
87
|
+
} from '@schema-hub/zod-graphql-client';
|
|
88
|
+
import { z } from 'zod';
|
|
89
|
+
|
|
90
|
+
const vars = defineVariables({ bar: z.string() });
|
|
91
|
+
|
|
92
|
+
const getFoo = defineQuery({
|
|
93
|
+
operationName: 'YourQueryName',
|
|
94
|
+
variables: vars,
|
|
95
|
+
schema: z
|
|
96
|
+
.object({
|
|
97
|
+
foo: graphqlFieldOptions(z.string(), { parameters: { bar: vars.bar } })
|
|
77
98
|
})
|
|
78
|
-
|
|
79
|
-
|
|
99
|
+
.strict()
|
|
100
|
+
});
|
|
80
101
|
|
|
81
|
-
// Send the query using the client
|
|
82
102
|
const client = createGraphqlClient({ endpoint: 'https://example.com/graphql' });
|
|
83
|
-
const result = await client.query(
|
|
84
|
-
operationName: 'YourQueryName', // Optional query name
|
|
85
|
-
variables: {
|
|
86
|
-
bar: {
|
|
87
|
-
type: 'String!',
|
|
88
|
-
value: 'the-actual-value-for-bar'
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
});
|
|
103
|
+
const result = await client.query(getFoo, { bar: 'the-actual-value-for-bar' });
|
|
92
104
|
|
|
93
105
|
console.log(result);
|
|
94
106
|
```
|
|
95
107
|
|
|
96
108
|
### Sending a Mutation
|
|
97
109
|
|
|
110
|
+
Mirror the query API with `defineMutation` and `client.mutate`:
|
|
111
|
+
|
|
98
112
|
```typescript
|
|
99
|
-
import {
|
|
113
|
+
import {
|
|
114
|
+
createGraphqlClient,
|
|
115
|
+
defineMutation,
|
|
116
|
+
defineVariables,
|
|
117
|
+
graphqlFieldOptions
|
|
118
|
+
} from '@schema-hub/zod-graphql-client';
|
|
100
119
|
import { z } from 'zod';
|
|
101
120
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
121
|
+
const vars = defineVariables({ bar: z.string() });
|
|
122
|
+
|
|
123
|
+
const sendFoo = defineMutation({
|
|
124
|
+
operationName: 'YourMutationName',
|
|
125
|
+
variables: vars,
|
|
126
|
+
schema: z
|
|
127
|
+
.object({
|
|
128
|
+
foo: graphqlFieldOptions(z.string(), { parameters: { bar: vars.bar } })
|
|
110
129
|
})
|
|
111
|
-
|
|
112
|
-
|
|
130
|
+
.strict()
|
|
131
|
+
});
|
|
113
132
|
|
|
114
|
-
// Send the mutation using the client
|
|
115
133
|
const client = createGraphqlClient({ endpoint: 'https://example.com/graphql' });
|
|
116
|
-
const result = await client.mutate(
|
|
117
|
-
operationName: 'YourMutationName', // Optional mutation name
|
|
118
|
-
variables: {
|
|
119
|
-
bar: {
|
|
120
|
-
type: 'String!',
|
|
121
|
-
value: 'the-actual-value-for-bar'
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
});
|
|
134
|
+
const result = await client.mutate(sendFoo, { bar: 'the-actual-value-for-bar' });
|
|
125
135
|
|
|
126
136
|
console.log(result);
|
|
127
137
|
```
|
|
128
138
|
|
|
139
|
+
### Defining Variables
|
|
140
|
+
|
|
141
|
+
`defineVariables` accepts a map of variable names to either:
|
|
142
|
+
|
|
143
|
+
1. A Zod schema for a primitive, in which case the GraphQL type is **inferred** from the schema; or
|
|
144
|
+
2. A `variable(type, schema)` entry that declares the GraphQL type explicitly (use this for input objects, enums, custom scalars, and any non-primitive types).
|
|
145
|
+
|
|
146
|
+
Both forms produce typed placeholders that you reference from `graphqlFieldOptions.parameters`, and a `parse` step that **runtime-validates** the values you pass to `client.query`/`client.mutate` against the Zod schemas before sending the request.
|
|
147
|
+
|
|
148
|
+
Primitive inference rules:
|
|
149
|
+
|
|
150
|
+
| Zod schema | Inferred GraphQL type |
|
|
151
|
+
| ------------------------------ | ----------------------- |
|
|
152
|
+
| `z.string()` | `String!` |
|
|
153
|
+
| `z.number()` | `Float!` |
|
|
154
|
+
| `z.int()` / `z.number().int()` | `Int!` |
|
|
155
|
+
| `z.boolean()` | `Boolean!` |
|
|
156
|
+
| `z.array(inner)` | `[<inner>]!` |
|
|
157
|
+
| `.nullable()` / `.nullish()` | strips the trailing `!` |
|
|
158
|
+
|
|
159
|
+
Anything outside this set (enums, objects, literals, unions, custom scalars, `ID`, …) cannot be inferred and must use the explicit form:
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
import { defineVariables, variable } from '@schema-hub/zod-graphql-client';
|
|
163
|
+
import { z } from 'zod';
|
|
164
|
+
|
|
165
|
+
const vars = defineVariables({
|
|
166
|
+
bar: z.string(), // inferred: String!
|
|
167
|
+
count: z.int().nullable(), // inferred: Int
|
|
168
|
+
filter: variable('FilterInput!', z.object({ query: z.string() })) // explicit type
|
|
169
|
+
});
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Operation Handles
|
|
173
|
+
|
|
174
|
+
`defineQuery` and `defineMutation` return an opaque `OperationHandle` that bundles the schema, variable map (if any), and operation name into a single artifact. `client.query` and `client.mutate` are overloaded so that:
|
|
175
|
+
|
|
176
|
+
- `client.query(schema)` / `client.query(handle)` — no values, used for variable-free operations.
|
|
177
|
+
- `client.query(handle, values)` — pass values for a handle that declares variables. `values` is statically type-checked against the variable map.
|
|
178
|
+
|
|
179
|
+
`operationName` lives on the handle, not on call-time options. To send the same schema under two different operation names, define two handles.
|
|
180
|
+
|
|
129
181
|
### Options for Queries and Mutations
|
|
130
182
|
|
|
131
|
-
- `operationName` (optional): The name of the query or mutation. This is useful for debugging and introspection purposes.
|
|
132
|
-
- `variables` (optional): A record of all variable values and types that should be included in the query or mutation. This allows you to parameterize your operations and provide dynamic values at runtime.
|
|
133
183
|
- `headers` (optional): A key-value map of additional headers that should be sent with the request. These headers will be merged with any headers specified when creating the client.
|
|
134
184
|
- `timeout` (optional): The request timeout in milliseconds. This determines how long the client will wait for a response before considering the request failed. If not specified, the default timeout specified when creating the client will be used.
|
|
135
185
|
|
|
@@ -184,13 +234,45 @@ Errors are distinguishable based on the `type` property within the `errorDetails
|
|
|
184
234
|
|
|
185
235
|
The `queryOrThrow()` and `mutateOrThrow()` functions behaves similarly to `query()` and `mutate()`, but with one key difference in its return type. If the operation execution is successful, the function returns the operation result data directly. However, if an error occurs during the operation execution, it throws an instance of `GraphqlOperationError`. This custom error contains detailed information about the encountered error in its `details` property, which aligns with the `errorDetails` structure returned by the `operation()` function.
|
|
186
236
|
|
|
237
|
+
### Automatic Persisted Queries (APQ)
|
|
238
|
+
|
|
239
|
+
When `persistedQueries` is enabled on the client, every operation is first sent as the SHA-256 hash of the serialized query (no `query` body), following Apollo’s [Automatic Persisted Queries](https://www.apollographql.com/docs/apollo-server/performance/apq/) protocol:
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
const client = createGraphqlClient({
|
|
243
|
+
endpoint: 'https://example.com/graphql',
|
|
244
|
+
persistedQueries: true
|
|
245
|
+
});
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
The request payload sent to the server uses the standard APQ extension format:
|
|
249
|
+
|
|
250
|
+
```json
|
|
251
|
+
{
|
|
252
|
+
"operationName": "YourQueryName",
|
|
253
|
+
"variables": {},
|
|
254
|
+
"extensions": {
|
|
255
|
+
"persistedQuery": {
|
|
256
|
+
"version": 1,
|
|
257
|
+
"sha256Hash": "<sha256 of the serialized query>"
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
The client automatically handles the two well-known APQ error responses:
|
|
264
|
+
|
|
265
|
+
- **`PersistedQueryNotFound`**: The server doesn’t yet know this query. The client retries the same operation, this time including both the `query` text and the `extensions.persistedQuery` envelope, so the server can register the query under its hash for future requests.
|
|
266
|
+
- **`PersistedQueryNotSupported`**: The server does not support APQ at all. The client retries the operation as a plain GraphQL request (no `extensions` field). Subsequent operations still attempt APQ — the client does not remember that the server doesn’t support it.
|
|
267
|
+
|
|
268
|
+
Detection of these error responses is resilient: the client matches both on `errors[].message` (`PersistedQueryNotFound` / `PersistedQueryNotSupported`) and on `errors[].extensions.code` (`PERSISTED_QUERY_NOT_FOUND` / `PERSISTED_QUERY_NOT_SUPPORTED`).
|
|
269
|
+
|
|
187
270
|
### Re-exported Functions
|
|
188
271
|
|
|
189
272
|
Some functions from `@schema-hub/zod-graphql-query-builder` are re-exported for convenience:
|
|
190
273
|
|
|
191
274
|
- `graphqlFieldOptions()`
|
|
192
275
|
- `enumValue()`
|
|
193
|
-
- `variablePlaceholder()`
|
|
194
276
|
- `customScalar()`
|
|
195
277
|
|
|
196
278
|
For more details, see the [`@schema-hub/zod-graphql-query-builder` documentation](../zod-graphql-query-builder/readme.md).
|
package/sbom.cdx.json
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://cyclonedx.org/schema/bom-1.6.schema.json",
|
|
3
|
+
"bomFormat": "CycloneDX",
|
|
4
|
+
"specVersion": "1.6",
|
|
5
|
+
"version": 1,
|
|
6
|
+
"metadata": {
|
|
7
|
+
"tools": {
|
|
8
|
+
"components": [
|
|
9
|
+
{
|
|
10
|
+
"type": "application",
|
|
11
|
+
"name": "packtory",
|
|
12
|
+
"version": "0.0.26"
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"component": {
|
|
17
|
+
"type": "library",
|
|
18
|
+
"name": "@schema-hub/zod-graphql-client",
|
|
19
|
+
"version": "0.0.15",
|
|
20
|
+
"bom-ref": "pkg:npm/@schema-hub/zod-graphql-client@0.0.15",
|
|
21
|
+
"purl": "pkg:npm/@schema-hub/zod-graphql-client@0.0.15"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"components": [
|
|
25
|
+
{
|
|
26
|
+
"type": "library",
|
|
27
|
+
"name": "@schema-hub/zod-error-formatter",
|
|
28
|
+
"version": "0.0.12",
|
|
29
|
+
"bom-ref": "pkg:npm/@schema-hub/zod-error-formatter@0.0.12",
|
|
30
|
+
"scope": "required",
|
|
31
|
+
"licenses": [
|
|
32
|
+
{
|
|
33
|
+
"expression": "MIT"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"purl": "pkg:npm/@schema-hub/zod-error-formatter@0.0.12"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"type": "library",
|
|
40
|
+
"name": "@schema-hub/zod-graphql-query-builder",
|
|
41
|
+
"version": "0.0.14",
|
|
42
|
+
"bom-ref": "pkg:npm/@schema-hub/zod-graphql-query-builder@0.0.14",
|
|
43
|
+
"scope": "required",
|
|
44
|
+
"licenses": [
|
|
45
|
+
{
|
|
46
|
+
"expression": "MIT"
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
"purl": "pkg:npm/@schema-hub/zod-graphql-query-builder@0.0.14"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"type": "library",
|
|
53
|
+
"name": "ky",
|
|
54
|
+
"version": "2.0.2",
|
|
55
|
+
"bom-ref": "pkg:npm/ky@2.0.2",
|
|
56
|
+
"scope": "required",
|
|
57
|
+
"licenses": [
|
|
58
|
+
{
|
|
59
|
+
"expression": "MIT"
|
|
60
|
+
}
|
|
61
|
+
],
|
|
62
|
+
"purl": "pkg:npm/ky@2.0.2"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"type": "library",
|
|
66
|
+
"name": "zod",
|
|
67
|
+
"version": "^4.0.5",
|
|
68
|
+
"bom-ref": "pkg:npm/zod@%5E4.0.5",
|
|
69
|
+
"scope": "optional",
|
|
70
|
+
"licenses": [
|
|
71
|
+
{
|
|
72
|
+
"expression": "MIT"
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
"purl": "pkg:npm/zod@%5E4.0.5"
|
|
76
|
+
}
|
|
77
|
+
],
|
|
78
|
+
"dependencies": [
|
|
79
|
+
{
|
|
80
|
+
"ref": "pkg:npm/@schema-hub/zod-error-formatter@0.0.12"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"ref": "pkg:npm/@schema-hub/zod-graphql-client@0.0.15",
|
|
84
|
+
"dependsOn": [
|
|
85
|
+
"pkg:npm/@schema-hub/zod-error-formatter@0.0.12",
|
|
86
|
+
"pkg:npm/@schema-hub/zod-graphql-query-builder@0.0.14",
|
|
87
|
+
"pkg:npm/ky@2.0.2",
|
|
88
|
+
"pkg:npm/zod@%5E4.0.5"
|
|
89
|
+
]
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"ref": "pkg:npm/@schema-hub/zod-graphql-query-builder@0.0.14"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"ref": "pkg:npm/ky@2.0.2"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"ref": "pkg:npm/zod@%5E4.0.5"
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
}
|
|
@@ -1,34 +1,20 @@
|
|
|
1
1
|
import { type KyInstance } from 'ky';
|
|
2
2
|
import type { output as TypeOf } from 'zod/v4/core';
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
5
|
-
import { type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
timeout?: number;
|
|
9
|
-
headers?: Record<string, string | undefined>;
|
|
10
|
-
variables?: Variables;
|
|
11
|
-
};
|
|
3
|
+
import type { QuerySchema } from '@schema-hub/zod-graphql-query-builder';
|
|
4
|
+
import type { MaybeVariables } from './define-variables.js';
|
|
5
|
+
import { type OperationCallArgs, type OperationHandle } from './operation-payload.js';
|
|
6
|
+
import type { OperationResult, OperationResultForType } from './operation-result.js';
|
|
7
|
+
export type { OperationOptions } from './operation-payload.js';
|
|
12
8
|
export type ClientOptions = {
|
|
13
9
|
endpoint: string;
|
|
14
10
|
headers?: Record<string, string | undefined>;
|
|
15
11
|
timeout?: number;
|
|
12
|
+
persistedQueries?: boolean;
|
|
16
13
|
};
|
|
17
14
|
export type GraphqlClient = {
|
|
18
|
-
readonly query: <Schema extends QuerySchema>(
|
|
19
|
-
readonly queryOrThrow: <Schema extends QuerySchema>(
|
|
20
|
-
readonly mutate: <Schema extends QuerySchema>(
|
|
21
|
-
readonly mutateOrThrow: <Schema extends QuerySchema>(
|
|
22
|
-
};
|
|
23
|
-
type CreateClientFn = (clientOptions: ClientOptions) => GraphqlClient;
|
|
24
|
-
export type CreateClientDependencies = {
|
|
25
|
-
ky: KyInstance;
|
|
26
|
-
};
|
|
27
|
-
export type GraphqlOverHttpOperationRequestPayload = {
|
|
28
|
-
query: string;
|
|
29
|
-
variables: Record<string, unknown>;
|
|
30
|
-
operationName?: string | undefined;
|
|
15
|
+
readonly query: <Schema extends QuerySchema, Variables extends MaybeVariables = undefined>(handle: OperationHandle<Schema, Variables>, ...rest: OperationCallArgs<Variables>) => Promise<OperationResult<Schema>>;
|
|
16
|
+
readonly queryOrThrow: <Schema extends QuerySchema, Variables extends MaybeVariables = undefined>(handle: OperationHandle<Schema, Variables>, ...rest: OperationCallArgs<Variables>) => Promise<TypeOf<Schema>>;
|
|
17
|
+
readonly mutate: <Schema extends QuerySchema, Variables extends MaybeVariables = undefined>(handle: OperationHandle<Schema, Variables>, ...rest: OperationCallArgs<Variables>) => Promise<OperationResult<Schema>>;
|
|
18
|
+
readonly mutateOrThrow: <Schema extends QuerySchema, Variables extends MaybeVariables = undefined>(handle: OperationHandle<Schema, Variables>, ...rest: OperationCallArgs<Variables>) => Promise<TypeOf<Schema>>;
|
|
31
19
|
};
|
|
32
|
-
export declare function createClientFactory(dependencies: CreateClientDependencies): CreateClientFn;
|
|
33
|
-
export {};
|
|
34
20
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAkD,MAAM,IAAI
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAkD,MAAM,IAAI;AACpF,OAAO,KAAK,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,aAAa;AAEnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM;AACjC,IAD8E,CAAC,EACxE,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB;AAG3D,OAAO,EAKH,KAAK,iBAAiB,EACtB,KAAK,eAAe,EAOvB,MAAM,wBAAwB;AAC/B,OAAO,KAAK,EAA0B,eAAe,EAAE,sBAAsB,EAAE,MAAM,uBAAuB;AAG5G,YAAY,EAAE,gBAAgB,EAAE,MAAM,wBAAwB;AAE9D,MAAM,MAAM,aAAa,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,MAAM,MAAM,aAAa,GAAG;IACxB,QAAQ,CAAC,KAAK,EAAE,CAAC,MAAM,SAAS,WAAW,EAAE,SAAS,SAAS,cAAc,GAAG,SAAS,EACrF,MAAM,EAAE,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,EAC1C,GAAG,IAAI,EAAE,iBAAiB,CAAC,SAAS,CAAC,KACpC,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;IACtC,QAAQ,CAAC,YAAY,EAAE,CAAC,MAAM,SAAS,WAAW,EAAE,SAAS,SAAS,cAAc,GAAG,SAAS,EAC5F,MAAM,EAAE,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,EAC1C,GAAG,IAAI,EAAE,iBAAiB,CAAC,SAAS,CAAC,KACpC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,CAAC,MAAM,SAAS,WAAW,EAAE,SAAS,SAAS,cAAc,GAAG,SAAS,EACtF,MAAM,EAAE,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,EAC1C,GAAG,IAAI,EAAE,iBAAiB,CAAC,SAAS,CAAC,KACpC,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;IACtC,QAAQ,CAAC,aAAa,EAAE,CAAC,MAAM,SAAS,WAAW,EAAE,SAAS,SAAS,cAAc,GAAG,SAAS,EAC7F,MAAM,EAAE,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,EAC1C,GAAG,IAAI,EAAE,iBAAiB,CAAC,SAAS,CAAC,KACpC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;CAChC"}
|