You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+92Lines changed: 92 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,6 +42,35 @@ You can check [example](https://github.com/Code-Hex/graphql-codegen-typescript-v
42
42
43
43
The Q&A for each schema is written in the README in the respective example directory.
44
44
45
+
### TypeScript config and presets
46
+
47
+
When you use `codegen.ts` with a preset such as `client`, put this plugin's options under the plugin entry. Some presets do not pass the shared generate-level `config` object to every plugin.
48
+
49
+
```ts
50
+
import type { CodegenConfig } from '@graphql-codegen/cli';
51
+
52
+
const config: CodegenConfig = {
53
+
schema: 'schema.graphql',
54
+
generates: {
55
+
'./src/gql/': {
56
+
preset: 'client',
57
+
plugins: [
58
+
{
59
+
'typescript-validation-schema': {
60
+
schema: 'zod',
61
+
scalarSchemas: {
62
+
DateTime: 'z.string().datetime()',
63
+
},
64
+
},
65
+
},
66
+
],
67
+
},
68
+
},
69
+
};
70
+
71
+
export default config;
72
+
```
73
+
45
74
## Config API Reference
46
75
47
76
### `schema`
@@ -283,12 +312,75 @@ It is currently added for the purpose of using simple objects. See also [#20](ht
283
312
284
313
This option currently **does not support fragment** generation. If you are interested, send me PR would be greatly appreciated!
285
314
315
+
### `withOperationType`
316
+
317
+
type: `boolean`default: `false`
318
+
319
+
Generates Zod schemas for GraphQL operation result selection sets.
320
+
Use this when `withObjectType` is too broad because it describes the full GraphQL object type, while your query only selects a subset of fields.
321
+
322
+
```yml
323
+
config:
324
+
schema: zod
325
+
withOperationType: true
326
+
```
327
+
328
+
Currently supported for `schema: zod` and `schema: zodv4`.
329
+
330
+
### `maxDepth`
331
+
332
+
type: `number`
333
+
334
+
Limits nested object validation depth for `withObjectType` schemas generated by `schema: zod` and `schema: zodv4`.
335
+
This is useful for cyclic output graphs where validating the entire object graph would recurse forever.
Controls how nullable GraphQL fields are generated for `schema: zod` and `schema: zodv4`.
355
+
The default `nullish` mode matches GraphQL input coercion, where a nullable input field may be omitted or passed as `null`.
356
+
Use `nullable` or `optional` only when your generated TypeScript `Maybe`/`InputMaybe` contract intentionally differs from GraphQL's default input coercion behavior.
357
+
358
+
```yml
359
+
config:
360
+
schema: zod
361
+
zodOptionalType: nullable
362
+
```
363
+
364
+
`nullishBehavior`is also accepted as an alias.
365
+
366
+
### `strictObjectSchemas`
367
+
368
+
type: `boolean`default: `false`
369
+
370
+
Appends `.strict()` to generated Zod object schemas.
371
+
372
+
### `withDescriptions`
373
+
374
+
type: `boolean`default: `false`
375
+
376
+
Appends `.describe()` to generated Zod fields from GraphQL descriptions.
0 commit comments