@nxgt/graphql-codegen-zod 0.2.1 → 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 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 anyway). Without the directive
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
@@ -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
- - **Output types.** Zod schemas and types for the SDL's object types,
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
@@ -159,6 +159,18 @@ query Both($e: String, $u: String) { e(v: $e) u(v: $u) }
159
159
  bun add @nxgt/graphql-scalars@latest
160
160
  ```
161
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
+
162
174
  ### `Property 'Money' does not exist on type '{ DateTime: ... }'` (or `TS2339`)
163
175
 
164
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.1",
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",
@@ -51,6 +51,7 @@
51
51
  },
52
52
  "devDependencies": {
53
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"