@nxgt/graphql-codegen-zod 0.0.0-stage → 0.2.0
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/LICENSE +21 -0
- package/README.md +232 -2
- package/dist/collect-fields.d.ts +24 -0
- package/dist/collect-fields.d.ts.map +1 -0
- package/dist/config.d.ts +53 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/cycles.d.ts +16 -0
- package/dist/cycles.d.ts.map +1 -0
- package/dist/defaults.d.ts +21 -0
- package/dist/defaults.d.ts.map +1 -0
- package/dist/imports.d.ts +14 -0
- package/dist/imports.d.ts.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1114 -0
- package/dist/index.js.map +25 -0
- package/dist/naming.d.ts +24 -0
- package/dist/naming.d.ts.map +1 -0
- package/dist/objects-output.d.ts +16 -0
- package/dist/objects-output.d.ts.map +1 -0
- package/dist/output-types.d.ts +15 -0
- package/dist/output-types.d.ts.map +1 -0
- package/dist/results-output.d.ts +16 -0
- package/dist/results-output.d.ts.map +1 -0
- package/dist/results-selections.d.ts +21 -0
- package/dist/results-selections.d.ts.map +1 -0
- package/dist/scalars.d.ts +21 -0
- package/dist/scalars.d.ts.map +1 -0
- package/dist/schema-output.d.ts +10 -0
- package/dist/schema-output.d.ts.map +1 -0
- package/dist/source.d.ts +9 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/type-code.d.ts +12 -0
- package/dist/type-code.d.ts.map +1 -0
- package/dist/variables-output.d.ts +13 -0
- package/dist/variables-output.d.ts.map +1 -0
- package/dist/writer.d.ts +36 -0
- package/dist/writer.d.ts.map +1 -0
- package/docs/README.md +14 -0
- package/docs/guide/output.md +732 -0
- package/docs/roadmap.md +38 -0
- package/docs/troubleshooting.md +267 -0
- package/package.json +62 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Steve Tsala
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,233 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nxgt/graphql-codegen-zod
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A [graphql-codegen](https://the-guild.dev/graphql/codegen) plugin that writes
|
|
4
|
+
Zod 4 schemas, and their TypeScript types, from your SDL: one per enum and per
|
|
5
|
+
input type, one per field that takes arguments, one per named operation's
|
|
6
|
+
variables, one per object type, interface and union, and one per named
|
|
7
|
+
operation's result and per fragment. It carries every `@constraint` of
|
|
8
|
+
[`@nxgt/graphql-validation`](https://www.npmjs.com/package/@nxgt/graphql-validation),
|
|
9
|
+
through that package's own rules, so the server (`withValidation`) and the
|
|
10
|
+
generated code accept and refuse the same values. For graphql-codegen 5 to 7
|
|
11
|
+
(ESM) and `graphql` 16 and 17.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
bun add -d @nxgt/graphql-codegen-zod @graphql-codegen/cli
|
|
17
|
+
bun add graphql zod typescript
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Peers, all **required**:
|
|
21
|
+
|
|
22
|
+
| Peer | Range |
|
|
23
|
+
| --- | --- |
|
|
24
|
+
| `graphql` | `^16.11.0 \|\| ^17.0.0` |
|
|
25
|
+
| `zod` | `>=4.6.5 <5` |
|
|
26
|
+
| `typescript` | `^6.0.3` |
|
|
27
|
+
|
|
28
|
+
`@nxgt/graphql-validation` is a dependency; you install it yourself only to
|
|
29
|
+
run `withValidation` on a server.
|
|
30
|
+
|
|
31
|
+
## Setup
|
|
32
|
+
|
|
33
|
+
Write the SDL files codegen reads: `@constraint` from
|
|
34
|
+
`@nxgt/graphql-validation` and the custom scalars from `@nxgt/graphql-scalars`.
|
|
35
|
+
Install both, so their bins are yours, whatever the package manager links:
|
|
36
|
+
`bun add @nxgt/graphql-validation @nxgt/graphql-scalars` (the generated file
|
|
37
|
+
imports `@nxgt/graphql-scalars` at run time anyway). Without the directive
|
|
38
|
+
nothing is constrained; plain types are still generated.
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
bunx nxgt-graphql-validation typedefs --out # generated/graphql/constraint.graphqls
|
|
42
|
+
bunx nxgt-graphql-scalars typedefs --out # generated/graphql/scalars.graphqls
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Both bins are described in the
|
|
46
|
+
[validation](https://www.npmjs.com/package/@nxgt/graphql-validation#ide-support)
|
|
47
|
+
and [scalars](https://www.npmjs.com/package/@nxgt/graphql-scalars#the-sdl-as-a-file)
|
|
48
|
+
READMEs. `typedefs DateTime Long --out` keeps only the scalars you use. Or skip the CLI and list
|
|
49
|
+
`node_modules/@nxgt/graphql-validation/graphql/constraint.graphqls` and
|
|
50
|
+
`node_modules/@nxgt/graphql-scalars/graphql/scalars.graphqls` in `schema`.
|
|
51
|
+
|
|
52
|
+
Then add the plugin, writing to **its own file**, with those files in `schema`:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
// codegen.ts
|
|
56
|
+
import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
57
|
+
|
|
58
|
+
const config: CodegenConfig = {
|
|
59
|
+
schema: [
|
|
60
|
+
'generated/graphql/constraint.graphqls',
|
|
61
|
+
'generated/graphql/scalars.graphqls',
|
|
62
|
+
'src/schema/**/*.graphql',
|
|
63
|
+
],
|
|
64
|
+
documents: 'src/operations/**/*.graphql',
|
|
65
|
+
generates: {
|
|
66
|
+
'src/generated/zod.ts': {
|
|
67
|
+
plugins: ['@nxgt/graphql-codegen-zod'],
|
|
68
|
+
config: { scalarSchemas: '@nxgt/graphql-scalars' },
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
export default config;
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The plugin writes types named as `@graphql-codegen/typescript` names them
|
|
76
|
+
(`SignUpInput`, `MutationSignUpArgs`), which would collide with that plugin's
|
|
77
|
+
in one file. Its `*Args` and `*Variables` types can replace the typescript
|
|
78
|
+
plugin's; so can its object types, interfaces and unions (`User`), or
|
|
79
|
+
`objects: false` leaves them to that plugin. Its `*Query`, `*Mutation` and
|
|
80
|
+
`*Fragment` types can replace typescript-operations' (`SearchQuery`,
|
|
81
|
+
`UserFieldsFragment`), or `operations: false` leaves them to it.
|
|
82
|
+
|
|
83
|
+
`scalarSchemas` supplies a Zod schema for each custom scalar of the schema;
|
|
84
|
+
see [Scalars](docs/guide/output.md#scalars).
|
|
85
|
+
|
|
86
|
+
Run codegen, once or on every change:
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
bunx graphql-codegen --config codegen.ts
|
|
90
|
+
bunx graphql-codegen --config codegen.ts --watch
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
or add `"codegen": "graphql-codegen"` to the `scripts` of `package.json` and
|
|
94
|
+
run `bun run codegen`.
|
|
95
|
+
|
|
96
|
+
## Usage
|
|
97
|
+
|
|
98
|
+
### On the server: type the resolvers
|
|
99
|
+
|
|
100
|
+
Arguments are typed `z.output`: what a resolver receives once
|
|
101
|
+
`withValidation` has parsed them.
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
import type { MutationSignUpArgs } from './generated/zod';
|
|
105
|
+
|
|
106
|
+
export const signUp = (_: unknown, { input }: MutationSignUpArgs) => {
|
|
107
|
+
// input.role is always set: its default was filled in
|
|
108
|
+
return { id: 'u_1', email: input.email };
|
|
109
|
+
};
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### On the server: type what a resolver returns
|
|
113
|
+
|
|
114
|
+
Object types, interfaces and unions are typed
|
|
115
|
+
`z.output`: custom scalars decoded, `__typename` optional, nullable fields
|
|
116
|
+
optional.
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import type { User } from './generated/zod';
|
|
120
|
+
|
|
121
|
+
export const me = (): User => ({ id: 'u_1', name: 'Al', joined: new Date() });
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`zUser.parse(value)` reads a wire value: a `DateTime` string becomes a
|
|
125
|
+
`Date`, and a field the schema does not declare is dropped. To check what a
|
|
126
|
+
resolver returns, which holds a `Date`, encode it back to the wire form:
|
|
127
|
+
`z.encode(zUser, value)`, or `z.safeEncode(zUser, value)` for a result. A
|
|
128
|
+
resolver's string for a `DateTime` is refused.
|
|
129
|
+
|
|
130
|
+
### On the client: check before sending
|
|
131
|
+
|
|
132
|
+
Variables are typed `z.input`: what a client sends. A schema per named
|
|
133
|
+
operation accepts and refuses what the server would.
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import { zSignUpMutationVariables } from './generated/zod';
|
|
137
|
+
|
|
138
|
+
const result = zSignUpMutationVariables.safeParse({
|
|
139
|
+
input: { email: form.email, name: form.name },
|
|
140
|
+
});
|
|
141
|
+
if (!result.success) {
|
|
142
|
+
for (const issue of result.error.issues) showError(issue.path, issue.message);
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### On the client: parse the response
|
|
147
|
+
|
|
148
|
+
An operation's result is typed `z.output`: what the response holds, custom
|
|
149
|
+
scalars decoded. An abstract type's selection is a union on `__typename` when
|
|
150
|
+
its members select different fields, so checking it narrows.
|
|
151
|
+
|
|
152
|
+
```graphql
|
|
153
|
+
query Search($text: String!) {
|
|
154
|
+
search(text: $text) {
|
|
155
|
+
__typename
|
|
156
|
+
... on User { id joined }
|
|
157
|
+
... on Post { id title }
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
import { zSearchQuery } from './generated/zod';
|
|
164
|
+
|
|
165
|
+
const search = zSearchQuery.parse(response.data).search;
|
|
166
|
+
for (const hit of search) {
|
|
167
|
+
if (hit.__typename === 'User') hit.joined.getFullYear(); // a Date
|
|
168
|
+
else hit.title; // Post
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
What is generated, how it is named, defaults, recursion, `@oneOf` and scalars
|
|
173
|
+
are in [Output](docs/guide/output.md).
|
|
174
|
+
|
|
175
|
+
## Options
|
|
176
|
+
|
|
177
|
+
| Option | Type | Default | Effect |
|
|
178
|
+
| --- | --- | --- | --- |
|
|
179
|
+
| `scalarSchemas` | `string` | none | module exporting a `scalarSchemas` record keyed by scalar name |
|
|
180
|
+
| `zodScalars` | `Record<string, string>` | none | `'<module>#<export>'` per scalar; wins over `scalarSchemas` |
|
|
181
|
+
| `schemaPrefix` | `string` | `'z'` | before each schema's name |
|
|
182
|
+
| `namingConvention` | `'keep' \| 'change-case-all#<case>' \| (name) => string \| { typeNames, transformUnderscore, enumValues }` | PascalCase per underscore part | how type names are cased, as the typescript plugins read it |
|
|
183
|
+
| `typesPrefix`, `typesSuffix` | `string` | none | around each type's name |
|
|
184
|
+
| `addUnderscoreToArgsType` | `boolean` | `false` | `Query_FindUserArgs` |
|
|
185
|
+
| `dedupeOperationSuffix`, `omitOperationSuffix` | `boolean` | `false` | as in `typescript-operations` |
|
|
186
|
+
| `objects` | `boolean` | `true` | write the object types, interfaces and unions; `false` writes no object types, interfaces or unions; results are still written unless `operations: false` |
|
|
187
|
+
| `operations` | `boolean` | `true` | write each named operation's result and each fragment; `false` writes none, the variables stay |
|
|
188
|
+
|
|
189
|
+
Each is detailed in [Output](docs/guide/output.md).
|
|
190
|
+
|
|
191
|
+
## Traps
|
|
192
|
+
|
|
193
|
+
- An `ID` is a string on the client: `graphql` also takes an `Int` for an
|
|
194
|
+
`ID`, the generated schema does not. Send `{ id: "5" }`.
|
|
195
|
+
- A single value for a list is taken, as `graphql` takes it, for every item
|
|
196
|
+
type and at any depth: `tags: "a"` parses to `["a"]`, `contacts: { phone }`
|
|
197
|
+
to `[{ phone }]`.
|
|
198
|
+
- An input type in a cycle (`Filter.and: [Filter]`) has its types written
|
|
199
|
+
out, `Filter` and `FilterInput`, and its schema is typed
|
|
200
|
+
`z.ZodType<Filter, FilterInput>`: it has no `.shape` or `.extend`.
|
|
201
|
+
- Input types are `z.strictObject`: a field the schema does not declare is
|
|
202
|
+
refused.
|
|
203
|
+
- A schema that declares `@constraint` must come from SDL files; an
|
|
204
|
+
introspected one fails generation.
|
|
205
|
+
- The plugin refuses a schema `withValidation` would refuse, with the same
|
|
206
|
+
message; those are in the
|
|
207
|
+
[validation troubleshooting](https://github.com/softistx/nxgt-graphql/blob/develop/packages/graphql-validation/docs/troubleshooting.md).
|
|
208
|
+
- A custom scalar mapped nowhere fails generation, naming it, rather than
|
|
209
|
+
becoming an unchecked `z.unknown()`.
|
|
210
|
+
- An abstract type whose possible types select different fields is a union on
|
|
211
|
+
`__typename`: select it, under one key for every member, or generation
|
|
212
|
+
fails. When they all select the same fields, no `__typename` is needed.
|
|
213
|
+
- A field under `@skip`, `@include` or `@defer` may be absent: it is
|
|
214
|
+
`.optional()`.
|
|
215
|
+
- Generate into a file of its own: the type names collide with the typescript
|
|
216
|
+
plugins', `*Query` and `*Fragment` with typescript-operations'. Take them from
|
|
217
|
+
this plugin, or set `objects: false` and `operations: false`.
|
|
218
|
+
- An input type in a cycle also declares `<Type>Input`, and an object type in a
|
|
219
|
+
cycle `<Type>Wire`: a GraphQL type of that name fails generation. Rename it,
|
|
220
|
+
or set `typesSuffix`.
|
|
221
|
+
- 0.1.0's output needs both `objects: false` and `operations: false`: a custom
|
|
222
|
+
scalar an operation selects needs a schema, whichever option is set alone.
|
|
223
|
+
|
|
224
|
+
Every error and its fix is in [Troubleshooting](docs/troubleshooting.md).
|
|
225
|
+
|
|
226
|
+
## Documentation
|
|
227
|
+
|
|
228
|
+
The package exports `plugin` and the `CodegenZodConfig` and `DocumentFile` types from `.`; graphql-codegen finds `plugin` by the package name. See [Output](docs/guide/output.md#the-plugin-function).
|
|
229
|
+
|
|
230
|
+
- [Documentation index](docs/README.md)
|
|
231
|
+
- Guides: [Output](docs/guide/output.md)
|
|
232
|
+
- [Troubleshooting](docs/troubleshooting.md)
|
|
233
|
+
- [Roadmap](docs/roadmap.md)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type FieldNode, type FragmentDefinitionNode, type GraphQLObjectType, type GraphQLSchema, type SelectionSetNode } from 'graphql';
|
|
2
|
+
/** A selection set, and whether the response may leave it out. */
|
|
3
|
+
export interface Selected {
|
|
4
|
+
readonly set: SelectionSetNode;
|
|
5
|
+
readonly conditional: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** A response key: its field, every node selecting it, if it may be absent. */
|
|
8
|
+
export interface Collected {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly nodes: {
|
|
11
|
+
readonly node: FieldNode;
|
|
12
|
+
readonly conditional: boolean;
|
|
13
|
+
}[];
|
|
14
|
+
optional: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The fields `sets` select on `type`, by response key, as graphql's
|
|
18
|
+
* CollectFields gathers them for every value of the variables: inline
|
|
19
|
+
* fragments and spreads whose type condition `type` satisfies, the same
|
|
20
|
+
* key's nodes merged, each node keeping whether it may be left out, so a
|
|
21
|
+
* sub-field only a conditional node selects stays optional.
|
|
22
|
+
*/
|
|
23
|
+
export declare function collectFields(schema: GraphQLSchema, fragments: ReadonlyMap<string, FragmentDefinitionNode>, type: GraphQLObjectType, sets: readonly Selected[]): Map<string, Collected>;
|
|
24
|
+
//# sourceMappingURL=collect-fields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collect-fields.d.ts","sourceRoot":"","sources":["../src/collect-fields.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,SAAS,EACd,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAIlB,KAAK,gBAAgB,EACrB,MAAM,SAAS,CAAC;AAEjB,kEAAkE;AAClE,MAAM,WAAW,QAAQ;IACxB,QAAQ,CAAC,GAAG,EAAE,gBAAgB,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;CAC9B;AAED,+EAA+E;AAC/E,MAAM,WAAW,SAAS;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;QAAC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;IAC9E,QAAQ,EAAE,OAAO,CAAC;CAClB;AAKD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC5B,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,sBAAsB,CAAC,EACtD,IAAI,EAAE,iBAAiB,EACvB,IAAI,EAAE,SAAS,QAAQ,EAAE,GACvB,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CA8CxB"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { DocumentNode } from 'graphql';
|
|
2
|
+
/**
|
|
3
|
+
* The plugin's options, under `config` in `codegen.ts`. The naming options
|
|
4
|
+
* mean what they mean to `@graphql-codegen/typescript`, so the types this
|
|
5
|
+
* plugin writes carry the names the typescript plugins give them.
|
|
6
|
+
*/
|
|
7
|
+
export interface CodegenZodConfig {
|
|
8
|
+
/**
|
|
9
|
+
* A module exporting `scalarSchemas`, a record of Zod schemas keyed by
|
|
10
|
+
* GraphQL scalar name: `'@nxgt/graphql-scalars'`, or a path relative to
|
|
11
|
+
* the generated file.
|
|
12
|
+
*/
|
|
13
|
+
readonly scalarSchemas?: string;
|
|
14
|
+
/**
|
|
15
|
+
* One scalar's schema, `'<module>#<export>'`, winning over
|
|
16
|
+
* `scalarSchemas`: `{ Money: './money#moneySchema' }`.
|
|
17
|
+
*/
|
|
18
|
+
readonly zodScalars?: Readonly<Record<string, string>>;
|
|
19
|
+
/** Before each schema's name: `zSignUpInput`. Default `'z'`. */
|
|
20
|
+
readonly schemaPrefix?: string;
|
|
21
|
+
/**
|
|
22
|
+
* As the typescript plugins read it, for type names: `'keep'`,
|
|
23
|
+
* `'change-case-all#<case>'`, a function, or `{ typeNames,
|
|
24
|
+
* transformUnderscore }`. Default: PascalCase each part between
|
|
25
|
+
* underscores.
|
|
26
|
+
*/
|
|
27
|
+
readonly namingConvention?: string | ((name: string) => string) | {
|
|
28
|
+
readonly typeNames?: string | ((name: string) => string);
|
|
29
|
+
readonly enumValues?: unknown;
|
|
30
|
+
readonly transformUnderscore?: boolean;
|
|
31
|
+
};
|
|
32
|
+
readonly typesPrefix?: string;
|
|
33
|
+
readonly typesSuffix?: string;
|
|
34
|
+
readonly addUnderscoreToArgsType?: boolean;
|
|
35
|
+
readonly dedupeOperationSuffix?: boolean;
|
|
36
|
+
readonly omitOperationSuffix?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* The SDL's object types, interfaces and unions, as what a resolver
|
|
39
|
+
* returns: `zUser`, `User`. Default `true`.
|
|
40
|
+
*/
|
|
41
|
+
readonly objects?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Each named operation's result and each fragment, as the response
|
|
44
|
+
* holds them: `zUserQuery`, `UserFieldsFragment`. Default `true`.
|
|
45
|
+
*/
|
|
46
|
+
readonly operations?: boolean;
|
|
47
|
+
}
|
|
48
|
+
/** A file of `documents`, as graphql-codegen hands it to a plugin. */
|
|
49
|
+
export interface DocumentFile {
|
|
50
|
+
readonly document?: DocumentNode | undefined;
|
|
51
|
+
readonly location?: string | undefined;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAChC;;;;OAIG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC;;;OAGG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACvD,gEAAgE;IAChE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B;;;;;OAKG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EACvB,MAAM,GACN,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC,GAC1B;QACA,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;QACzD,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;QAC9B,QAAQ,CAAC,mBAAmB,CAAC,EAAE,OAAO,CAAC;KACtC,CAAC;IACL,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAC3C,QAAQ,CAAC,qBAAqB,CAAC,EAAE,OAAO,CAAC;IACzC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IACvC;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B;;;OAGG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,sEAAsE;AACtE,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC;IAC7C,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACvC"}
|
package/dist/cycles.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type GraphQLSchema } from 'graphql';
|
|
2
|
+
/**
|
|
3
|
+
* The input types that reach themselves through their fields, directly
|
|
4
|
+
* (`Filter.and: [Filter]`) or through others: TypeScript cannot infer the
|
|
5
|
+
* schema of such a type once a field wraps it, so the plugin writes their
|
|
6
|
+
* types out.
|
|
7
|
+
*/
|
|
8
|
+
export declare function inputCycles(schema: GraphQLSchema): ReadonlySet<string>;
|
|
9
|
+
/**
|
|
10
|
+
* The object types that reach themselves through their fields, an
|
|
11
|
+
* interface's or a union's members included: TypeScript infers such a
|
|
12
|
+
* schema only so deep (TS2589 past a loop of ten), so the plugin writes
|
|
13
|
+
* their types out.
|
|
14
|
+
*/
|
|
15
|
+
export declare function outputCycles(schema: GraphQLSchema): ReadonlySet<string>;
|
|
16
|
+
//# sourceMappingURL=cycles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cycles.d.ts","sourceRoot":"","sources":["../src/cycles.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,aAAa,EAMlB,MAAM,SAAS,CAAC;AAEjB;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,aAAa,GAAG,WAAW,CAAC,MAAM,CAAC,CAUtE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,WAAW,CAAC,MAAM,CAAC,CAavE"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ConstValueNode, type GraphQLArgument, type GraphQLInputField, type GraphQLInputType } from 'graphql';
|
|
2
|
+
/**
|
|
3
|
+
* A default's value as the client parses it: its literal coerced as
|
|
4
|
+
* graphql coerces it. An integer a JavaScript number cannot keep exact,
|
|
5
|
+
* given to an ID or a custom scalar, fails, naming `where`: the server
|
|
6
|
+
* would hand the scalar every digit. An Int or a Float rounds on both sides.
|
|
7
|
+
*/
|
|
8
|
+
export declare function parsedDefault(literal: ConstValueNode, type: GraphQLInputType, where: string): unknown;
|
|
9
|
+
/**
|
|
10
|
+
* The default of an argument or input field as a literal: its SDL's, or,
|
|
11
|
+
* for a schema built without SDL (introspected), its value written back.
|
|
12
|
+
* graphql 16 holds that value in `defaultValue`, graphql 17 in `default`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function defaultLiteral(input: GraphQLArgument | GraphQLInputField): ConstValueNode | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* A default as graphql coerces it, through lists and input objects: a
|
|
17
|
+
* single value given for a list is a list of it (`[String!] = "a"` is
|
|
18
|
+
* `["a"]`, `[[Int]] = 1` is `[[1]]`), at any depth.
|
|
19
|
+
*/
|
|
20
|
+
export declare function coerced(value: unknown, type: GraphQLInputType): unknown;
|
|
21
|
+
//# sourceMappingURL=defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,KAAK,cAAc,EACnB,KAAK,eAAe,EAEpB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EAUrB,MAAM,SAAS,CAAC;AAEjB;;;;;GAKG;AACH,wBAAgB,aAAa,CAC5B,OAAO,EAAE,cAAc,EACvB,IAAI,EAAE,gBAAgB,EACtB,KAAK,EAAE,MAAM,GACX,OAAO,CAGT;AAmCD;;;;GAIG;AACH,wBAAgB,cAAc,CAC7B,KAAK,EAAE,eAAe,GAAG,iBAAiB,GACxC,cAAc,GAAG,SAAS,CAyB5B;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAoBvE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The named imports of the generated file, one line per module, an alias
|
|
3
|
+
* when two modules export the same name.
|
|
4
|
+
*/
|
|
5
|
+
export declare class Imports {
|
|
6
|
+
#private;
|
|
7
|
+
/** `reserved`: the names the file declares, which no import may take. */
|
|
8
|
+
constructor(reserved?: Iterable<string>);
|
|
9
|
+
/** The local name `exported` from `module` is reached by. */
|
|
10
|
+
add(module: string, exported: string): string;
|
|
11
|
+
/** The import lines, `zod` first, double-quoted as every string the file holds. */
|
|
12
|
+
lines(): string[];
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=imports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imports.d.ts","sourceRoot":"","sources":["../src/imports.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,OAAO;;IAMnB,yEAAyE;gBAC7D,QAAQ,GAAE,QAAQ,CAAC,MAAM,CAAM;IAI3C,6DAA6D;IAC7D,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;IAY7C,mFAAmF;IACnF,KAAK,IAAI,MAAM,EAAE;CAUjB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type GraphQLSchema } from 'graphql';
|
|
2
|
+
import type { CodegenZodConfig, DocumentFile } from './config';
|
|
3
|
+
export type { CodegenZodConfig, DocumentFile } from './config';
|
|
4
|
+
/**
|
|
5
|
+
* The graphql-codegen plugin: Zod schemas, and their types, for the
|
|
6
|
+
* schema's enums, input types, field arguments, object types, interfaces and
|
|
7
|
+
* unions, and for the variables of each operation in `documents`, with every `@constraint` of
|
|
8
|
+
* `@nxgt/graphql-validation`. It refuses a schema `withValidation` would
|
|
9
|
+
* refuse, with the same message.
|
|
10
|
+
*/
|
|
11
|
+
export declare function plugin(schema: GraphQLSchema, documents: readonly DocumentFile[], config?: CodegenZodConfig, info?: {
|
|
12
|
+
readonly outputFile?: string | undefined;
|
|
13
|
+
}): Promise<string>;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,aAAa,EAIlB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAU/D,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE/D;;;;;;GAMG;AACH,wBAAsB,MAAM,CAC3B,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,SAAS,YAAY,EAAE,EAClC,MAAM,GAAE,gBAAqB,EAC7B,IAAI,CAAC,EAAE;IAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GACjD,OAAO,CAAC,MAAM,CAAC,CAqCjB"}
|