@nxgt/graphql-codegen-zod 0.2.0 → 0.2.2
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/README.md +6 -1
- package/dist/index.d.ts +2 -2
- package/dist/naming.d.ts +1 -1
- package/dist/objects-output.d.ts +2 -2
- package/dist/output-types.d.ts +2 -2
- package/dist/results-output.d.ts +3 -3
- package/dist/results-selections.d.ts +2 -2
- package/dist/scalars.d.ts +2 -2
- package/dist/schema-output.d.ts +2 -2
- package/dist/source.d.ts +2 -2
- package/dist/type-code.d.ts +2 -2
- package/dist/variables-output.d.ts +3 -3
- package/dist/writer.d.ts +2 -2
- package/docs/guide/output.md +34 -1
- package/docs/roadmap.md +8 -4
- package/docs/troubleshooting.md +24 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -34,7 +34,8 @@ Write the SDL files codegen reads: `@constraint` from
|
|
|
34
34
|
`@nxgt/graphql-validation` and the custom scalars from `@nxgt/graphql-scalars`.
|
|
35
35
|
Install both, so their bins are yours, whatever the package manager links:
|
|
36
36
|
`bun add @nxgt/graphql-validation @nxgt/graphql-scalars` (the generated file
|
|
37
|
-
imports `@nxgt/graphql-scalars` at run time
|
|
37
|
+
imports `@nxgt/graphql-scalars` at run time, unless it takes `@nxgt/zod`; see
|
|
38
|
+
below). Without the directive
|
|
38
39
|
nothing is constrained; plain types are still generated.
|
|
39
40
|
|
|
40
41
|
```sh
|
|
@@ -72,6 +73,10 @@ const config: CodegenConfig = {
|
|
|
72
73
|
export default config;
|
|
73
74
|
```
|
|
74
75
|
|
|
76
|
+
A client that only runs the generated file can set
|
|
77
|
+
`scalarSchemas: '@nxgt/zod'` instead: the same record, without `graphql`. See
|
|
78
|
+
[On a client](docs/guide/output.md#on-a-client-nxgtzod).
|
|
79
|
+
|
|
75
80
|
The plugin writes types named as `@graphql-codegen/typescript` names them
|
|
76
81
|
(`SignUpInput`, `MutationSignUpArgs`), which would collide with that plugin's
|
|
77
82
|
in one file. Its `*Args` and `*Variables` types can replace the typescript
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type GraphQLSchema } from 'graphql';
|
|
2
|
-
import type { CodegenZodConfig, DocumentFile } from './config';
|
|
3
|
-
export type { CodegenZodConfig, DocumentFile } from './config';
|
|
2
|
+
import type { CodegenZodConfig, DocumentFile } from './config.js';
|
|
3
|
+
export type { CodegenZodConfig, DocumentFile } from './config.js';
|
|
4
4
|
/**
|
|
5
5
|
* The graphql-codegen plugin: Zod schemas, and their types, for the
|
|
6
6
|
* schema's enums, input types, field arguments, object types, interfaces and
|
package/dist/naming.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { OperationTypeNode } from 'graphql';
|
|
2
|
-
import type { CodegenZodConfig } from './config';
|
|
2
|
+
import type { CodegenZodConfig } from './config.js';
|
|
3
3
|
/**
|
|
4
4
|
* The names of what the plugin writes: each type as
|
|
5
5
|
* `@graphql-codegen/typescript` and `typescript-operations` name it, each
|
package/dist/objects-output.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type GraphQLSchema } from 'graphql';
|
|
2
|
-
import type { Naming } from './naming';
|
|
3
|
-
import type { Writer } from './writer';
|
|
2
|
+
import type { Naming } from './naming.js';
|
|
3
|
+
import type { Writer } from './writer.js';
|
|
4
4
|
/** The built-in scalars' schemas on the way out. */
|
|
5
5
|
export declare const builtIns: Readonly<Record<string, string>>;
|
|
6
6
|
/**
|
package/dist/output-types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type GraphQLObjectType } from 'graphql';
|
|
2
|
-
import type { Naming } from './naming';
|
|
3
|
-
import type { Writer } from './writer';
|
|
2
|
+
import type { Naming } from './naming.js';
|
|
3
|
+
import type { Writer } from './writer.js';
|
|
4
4
|
/**
|
|
5
5
|
* An object type in a cycle, declared with its types written out, as an
|
|
6
6
|
* input type in a cycle is: `User` (what a resolver returns, scalars
|
package/dist/results-output.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type GraphQLSchema } from 'graphql';
|
|
2
|
-
import type { DocumentFile } from './config';
|
|
3
|
-
import type { Naming } from './naming';
|
|
4
|
-
import type { Writer } from './writer';
|
|
2
|
+
import type { DocumentFile } from './config.js';
|
|
3
|
+
import type { Naming } from './naming.js';
|
|
4
|
+
import type { Writer } from './writer.js';
|
|
5
5
|
/**
|
|
6
6
|
* One schema per fragment and per named operation in `documents`, for the
|
|
7
7
|
* response as it arrives: what was selected, under its alias, custom
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type FragmentDefinitionNode, type GraphQLCompositeType, type GraphQLSchema } from 'graphql';
|
|
2
|
-
import { type Selected } from './collect-fields';
|
|
3
|
-
import type { Writer } from './writer';
|
|
2
|
+
import { type Selected } from './collect-fields.js';
|
|
3
|
+
import type { Writer } from './writer.js';
|
|
4
4
|
/**
|
|
5
5
|
* The schema of a selection, for a response: what was selected, under its
|
|
6
6
|
* alias. Deep selections are declared apart, as `<schema>$<n>`, which the
|
package/dist/scalars.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { GraphQLScalarType } from 'graphql';
|
|
2
|
-
import type { CodegenZodConfig } from './config';
|
|
3
|
-
import type { Imports } from './imports';
|
|
2
|
+
import type { CodegenZodConfig } from './config.js';
|
|
3
|
+
import type { Imports } from './imports.js';
|
|
4
4
|
/**
|
|
5
5
|
* Where each custom scalar's schema comes from: `zodScalars` first, then the
|
|
6
6
|
* `scalarSchemas` record. A scalar in neither fails generation, naming it:
|
package/dist/schema-output.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type GraphQLSchema } from 'graphql';
|
|
2
|
-
import type { Naming } from './naming';
|
|
3
|
-
import type { Writer } from './writer';
|
|
2
|
+
import type { Naming } from './naming.js';
|
|
3
|
+
import type { Writer } from './writer.js';
|
|
4
4
|
/**
|
|
5
5
|
* The SDL's part of the file: every enum, then every input type, then the
|
|
6
6
|
* arguments of every object and interface field that takes any. Types are
|
package/dist/source.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Naming } from './naming';
|
|
2
|
-
import type { ValueCode } from './writer';
|
|
1
|
+
import type { Naming } from './naming.js';
|
|
2
|
+
import type { ValueCode } from './writer.js';
|
|
3
3
|
/** A GraphQL description as a doc comment, or nothing. */
|
|
4
4
|
export declare function docComment(description: string | null | undefined, indent?: string): string;
|
|
5
5
|
/** The members of a `z.object({...})`, a getter for each lazy one. */
|
package/dist/type-code.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type GraphQLInputObjectType } from 'graphql';
|
|
2
|
-
import type { Naming } from './naming';
|
|
3
|
-
import type { Writer } from './writer';
|
|
2
|
+
import type { Naming } from './naming.js';
|
|
3
|
+
import type { Writer } from './writer.js';
|
|
4
4
|
/**
|
|
5
5
|
* An input type in a cycle, declared with its types written out, since
|
|
6
6
|
* TypeScript cannot infer them: `Filter` (what the resolver receives),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type GraphQLSchema } from 'graphql';
|
|
2
|
-
import type { DocumentFile } from './config';
|
|
3
|
-
import type { Naming } from './naming';
|
|
4
|
-
import type { Writer } from './writer';
|
|
2
|
+
import type { DocumentFile } from './config.js';
|
|
3
|
+
import type { Naming } from './naming.js';
|
|
4
|
+
import type { Writer } from './writer.js';
|
|
5
5
|
/**
|
|
6
6
|
* One schema per named operation in `documents`, for its variables as a
|
|
7
7
|
* client sends them (`z.input`). A variable gets the constraints of every
|
package/dist/writer.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Constraint } from '@nxgt/graphql-validation/codegen';
|
|
2
2
|
import { type ConstValueNode, type GraphQLDirective, type GraphQLInputType, type GraphQLNamedInputType, type GraphQLScalarType } from 'graphql';
|
|
3
|
-
import type { Naming } from './naming';
|
|
4
|
-
import type { ScalarSources } from './scalars';
|
|
3
|
+
import type { Naming } from './naming.js';
|
|
4
|
+
import type { ScalarSources } from './scalars.js';
|
|
5
5
|
/** One value's schema as source, and whether it names an input object. */
|
|
6
6
|
export interface ValueCode {
|
|
7
7
|
readonly code: string;
|
package/docs/guide/output.md
CHANGED
|
@@ -413,7 +413,7 @@ A custom scalar needs a Zod schema from you, mapped in one of two ways:
|
|
|
413
413
|
|
|
414
414
|
| Option | Type | Effect |
|
|
415
415
|
| --- | --- | --- |
|
|
416
|
-
| `scalarSchemas` | `string` | a module exporting a `scalarSchemas` record keyed by GraphQL name; `@nxgt/graphql-scalars` exports one from 0.4.0 |
|
|
416
|
+
| `scalarSchemas` | `string` | a module exporting a `scalarSchemas` record keyed by GraphQL name; `@nxgt/graphql-scalars` exports one from 0.4.0, `@nxgt/zod` from 0.1.0 |
|
|
417
417
|
| `zodScalars` | `Record<string, string>` | `'<module>#<export>'` for one scalar; wins over the record |
|
|
418
418
|
|
|
419
419
|
```ts
|
|
@@ -435,6 +435,39 @@ birth: scalarSchemas.DateTime.nullish(),
|
|
|
435
435
|
price: moneySchema,
|
|
436
436
|
```
|
|
437
437
|
|
|
438
|
+
### On a client: `@nxgt/zod`
|
|
439
|
+
|
|
440
|
+
`@nxgt/zod` exports the same `scalarSchemas` record, with the rules of
|
|
441
|
+
`@nxgt/graphql-scalars`, and does not depend on `graphql`. A client that only
|
|
442
|
+
runs the generated file imports it instead, and keeps `graphql` out of its
|
|
443
|
+
bundle:
|
|
444
|
+
|
|
445
|
+
```ts
|
|
446
|
+
config: { scalarSchemas: '@nxgt/zod' },
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
```ts
|
|
450
|
+
// what the generated file imports
|
|
451
|
+
import { z } from "zod";
|
|
452
|
+
import { scalarSchemas } from "@nxgt/zod";
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
The generated schemas are the same either way; only the import changes. The
|
|
456
|
+
SDL codegen reads still comes from `@nxgt/graphql-scalars`
|
|
457
|
+
(`bunx nxgt-graphql-scalars typedefs --out`), so a client installs it as a
|
|
458
|
+
devDependency and `@nxgt/zod` as a dependency. Everything codegen needs is a
|
|
459
|
+
devDependency too, so `graphql` never reaches the bundle: the generated file
|
|
460
|
+
imports only `zod` and `@nxgt/zod`.
|
|
461
|
+
|
|
462
|
+
```sh
|
|
463
|
+
bun add @nxgt/zod zod
|
|
464
|
+
bun add -d @nxgt/graphql-codegen-zod @nxgt/graphql-validation @nxgt/graphql-scalars
|
|
465
|
+
bun add -d graphql @graphql-codegen/cli typescript
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
Under `moduleResolution` `nodenext` or `node16`, use `@nxgt/zod` 0.1.2 or
|
|
469
|
+
later.
|
|
470
|
+
|
|
438
471
|
- Two exports with the same name from different modules are aliased:
|
|
439
472
|
`import { schema } from "./money"; import { schema as schema2 } from "./cost";`.
|
|
440
473
|
- Module paths are written as they are in the generated file, so a relative
|
package/docs/roadmap.md
CHANGED
|
@@ -4,10 +4,7 @@ What `@nxgt/graphql-codegen-zod` is heading for, phrased as what you get.
|
|
|
4
4
|
|
|
5
5
|
## Now
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
interfaces and unions, and for each named operation's result and each
|
|
9
|
-
fragment, with `__typename` discriminating abstract types. Both parts are
|
|
10
|
-
written; they ship with the next release.
|
|
7
|
+
Nothing in progress.
|
|
11
8
|
|
|
12
9
|
## Next
|
|
13
10
|
|
|
@@ -32,6 +29,13 @@ Nothing yet.
|
|
|
32
29
|
|
|
33
30
|
## Shipped
|
|
34
31
|
|
|
32
|
+
- **Declarations that resolve under `nodenext`, 0.2.1.** The generated
|
|
33
|
+
file's `scalarSchemas` import typechecks with `moduleResolution`
|
|
34
|
+
`nodenext` or `node16`, with `@nxgt/graphql-scalars` 0.4.1 or later.
|
|
35
|
+
- **Output types, 0.2.0.** Zod schemas and types for the SDL's object types,
|
|
36
|
+
interfaces and unions, and for each named operation's result and each
|
|
37
|
+
fragment, with `__typename` discriminating abstract types; `objects: false`
|
|
38
|
+
or `operations: false` turns either part off.
|
|
35
39
|
- **The first release, 0.1.0.** Zod 4 schemas and types for enums, input
|
|
36
40
|
types, field arguments and operation variables, carrying every
|
|
37
41
|
`@constraint` of `@nxgt/graphql-validation`, so the client refuses what the
|
package/docs/troubleshooting.md
CHANGED
|
@@ -147,6 +147,30 @@ query Both($e: String, $u: String) { e(v: $e) u(v: $u) }
|
|
|
147
147
|
|
|
148
148
|
## The generated file
|
|
149
149
|
|
|
150
|
+
### `TS2305: Module '"@nxgt/graphql-scalars"' has no exported member 'scalarSchemas'`
|
|
151
|
+
|
|
152
|
+
**When:** type-checking the generated file under `moduleResolution`
|
|
153
|
+
`nodenext` or `node16`, with `scalarSchemas: '@nxgt/graphql-scalars'`.
|
|
154
|
+
**Why:** `@nxgt/graphql-scalars` before 0.4.1 ships declarations that
|
|
155
|
+
`nodenext` does not resolve.
|
|
156
|
+
**Fix:** upgrade it to 0.4.1 or later.
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
bun add @nxgt/graphql-scalars@latest
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### `TS2305: Module '"@nxgt/zod"' has no exported member 'scalarSchemas'`
|
|
163
|
+
|
|
164
|
+
**When:** type-checking the generated file under `moduleResolution`
|
|
165
|
+
`nodenext` or `node16`, with `scalarSchemas: '@nxgt/zod'`.
|
|
166
|
+
**Why:** `@nxgt/zod` before 0.1.2 ships declarations that `nodenext` does not
|
|
167
|
+
resolve.
|
|
168
|
+
**Fix:** upgrade it to 0.1.2 or later.
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
bun add @nxgt/zod@latest
|
|
172
|
+
```
|
|
173
|
+
|
|
150
174
|
### `Property 'Money' does not exist on type '{ DateTime: ... }'` (or `TS2339`)
|
|
151
175
|
|
|
152
176
|
**When:** type-checking the generated file, with `scalarSchemas` set.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxgt/graphql-codegen-zod",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "A graphql-codegen plugin that writes Zod schemas from your SDL — inputs, enums, field arguments, operation variables, operation results and output types — with the @constraint rules of @nxgt/graphql-validation",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -46,11 +46,12 @@
|
|
|
46
46
|
"generated:write": "bun run test/write-generated.ts"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@nxgt/graphql-validation": "^0.2.
|
|
49
|
+
"@nxgt/graphql-validation": "^0.2.1",
|
|
50
50
|
"change-case": "^5.4.4"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@nxgt/graphql-scalars": "^0.4.
|
|
53
|
+
"@nxgt/graphql-scalars": "^0.4.1",
|
|
54
|
+
"@nxgt/zod": "^0.1.2",
|
|
54
55
|
"@types/bun": "^1.4.0",
|
|
55
56
|
"graphql": "16.11.0",
|
|
56
57
|
"zod": "4.6.5"
|