Registry / testing / graphql-codegen-typescript-validation-schema

graphql-codegen-typescript-validation-schema

JSON →
library0.19.0jsnpmunverified

GraphQL Code Generator plugin that generates form validation schemas (yup, zod, myzod, valibot) from your GraphQL schema. Current stable version 0.19.0. Releases are frequent; supports multiple validator libraries including zod v4. Key differentiator: automates creating consistent validation logic from GraphQL type definitions, reducing duplication between schema and client validation. Supports scalars, custom schemas, and strict mode. Requires graphql and a validator peer dependency.

npm install graphql-codegen-typescript-validation-schema
INSTALL
IMPORT
SIG · GRAPHQL-CODEGEN-TY
G
graphql-codegen-typescript-validation-schema
testingjavascriptv0.19.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

typescript-validation-schema plugin
plugins: [{ 'typescript-validation-schema': { schema: 'zodv4' } }]
plugins: ['typescript-validation-schema']
Use object form with plugin name as key to pass options. Array form does not accept config.
CodegenConfig
import type { CodegenConfig } from '@graphql-codegen/cli'
import { CodegenConfig } from '@graphql-codegen/cli'
Use type import for CodegenConfig; it is only a type.
scalarSchemas
scalarSchemas: { DateTime: 'z.string().datetime()' }
scalarSchemas: { DateTime: z.string().datetime() }
scalarSchemas values are strings that become part of the generated code, not actual Zod objects.

Configures graphql-codegen to generate Zod v4 validation schemas from a GraphQL schema file, including scalar mappings and strict mode.

// codegen.ts import type { CodegenConfig } from '@graphql-codegen/cli'; const config: CodegenConfig = { schema: './schema.graphql', generates: { './src/validation.ts': { plugins: [ 'typescript', { 'typescript-validation-schema': { schema: 'zodv4', scalarSchemas: { DateTime: 'z.string().datetime()', }, }, }, ], config: { scalars: { ID: { input: 'string', output: 'string' }, DateTime: { input: 'string', output: 'string' }, }, strictScalars: true, }, }, }, }; export default config; // Run: npx graphql-codegen --config codegen.ts
Debug
Known issues
deprecatedYAML configuration is deprecated; use TypeScript config file for better typing.
fix
Switch to codegen.ts with CodegenConfig type import.
affects: >=0.18.0
breakingID scalar default mapping was changed to avoid validation mismatch. See PR #375.
fix
Ensure scalars.ID is mapped to { input: 'string', output: 'string' } in codegen config.
affects: >0.12.0 <0.20.0
gotchaThe 'scalarSchemas' option uses string values, not validator instances.
fix
Write scalar schema as a string that will be output in generated code, e.g., 'z.string().datetime()'.
affects: >=0.1.0
gotchaThe 'schema' option in plugin config must match the validator installed (e.g., 'zodv4' for zod v4).
fix
Install the appropriate validator package and set the 'schema' field to the correct key: 'yup', 'zod', 'zodv4', 'myzod', or 'valibot'.
affects: >=0.13.0
gotchaplugins array order matters: place 'typescript' before 'typescript-validation-schema'.
fix
Order plugins: ['typescript', { 'typescript-validation-schema': ... }].
affects: >=0.1.0
breakingPeer dependency graphql may need to be upgraded for schema validation.
fix
Ensure graphql version satisfies ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0.
affects: >=0.19.0
deprecatedRoot or output-level config for validation-specific options is deprecated; use plugin-level config.
fix
Move options like 'scalarSchemas' into the plugin config object.
affects: >=0.18.0
Errors
Common errors & fixes
Cannot find module 'zod'
Missing zod peer dependency.
fix
Run: npm install zod
Unknown plugin 'typescript-validation-schema'
Plugin not installed as dev dependency.
fix
Run: npm install -D graphql-codegen-typescript-validation-schema
Type 'string' is not assignable to type 'ZodTypeAny'
Using string in 'scalarSchemas' instead of a string literal.
fix
Wrap the value in quotes: 'z.string().datetime()' instead of z.string().datetime()
The 'schema' option must be one of: yup, zod, zodv4, myzod, valibot
Invalid validator name in plugin config.
fix
Set 'schema' to a valid value: 'zodv4' for Zod v4.
Upgrade
Version history
0.19.0latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency; required for GraphQL schema processing.
@graphql-codegen/clioptionalPeer dependency; required to run code generation.
@graphql-codegen/typescriptrequiredPeer dependency; required to generate TypeScript types from GraphQL schema.
Agent activity
6 hits · last 30 days
node
6
Resources