{"id":47832,"library":"graphql-codegen-zod","title":"GraphQL Codegen Zod","description":"A GraphQL codegen plugin that generates Zod schemas from GraphQL input types. Version 1.10.6 is stable, actively maintained. It allows developers to define validation rules via GraphQL directives (@validation) or rely on required fields only. Key differentiator: keeps GraphQL as single source of truth for validation, supports custom scalar mappings, and integrates with GraphQL Code Generator ecosystem.","status":"active","version":"1.10.6","language":"javascript","source_language":"en","source_url":"https://github.com/withshepherd/graphql-codegen-zod","tags":["javascript"],"install":[{"cmd":"npm install graphql-codegen-zod","lang":"bash","label":"npm"},{"cmd":"yarn add graphql-codegen-zod","lang":"bash","label":"yarn"},{"cmd":"pnpm add graphql-codegen-zod","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used internally by graphql-codegen-zod for plugin infrastructure","package":"@graphql-codegen/plugin-helpers","optional":false},{"reason":"Peer dependency; required for generated schemas to work","package":"zod","optional":false}],"imports":[{"note":"Plugin is declared by its npm package name in codegen.yml, not imported in JavaScript.","wrong":"plugins:\n  - @graphql-codegen/zod","symbol":"graphql-codegen-zod","correct":"plugins:\n  - graphql-codegen-zod"},{"note":"Generated output is ESM by default; use named imports. CJS requires .default or esModuleInterop.","wrong":"const TestInput = require('./generated/schemas').TestInput;","symbol":"Zod schemas","correct":"import { TestInput } from './generated/schemas';"},{"note":"Directive must include all parameters to use advanced validations; otherwise only required checks work.","wrong":"directive @validation on INPUT_FIELD_DEFINITION","symbol":"Directive","correct":"directive @validation(pattern: String, min: Int, max: Int, requiredMessage: String, typeOf: String) on INPUT_FIELD_DEFINITION | ARGUMENT_DEFINITION"}],"quickstart":{"code":"// codegen.yml\noverwrite: true\nschema: './schema.graphql'\ngenerates:\n  schemas.ts:\n    plugins:\n      - graphql-codegen-zod:\n          onlyWithValidation: false\n\n// schema.graphql\ndirective @validation(\n  pattern: String\n  min: Int\n  max: Int\n  requiredMessage: String\n  typeOf: String\n) on INPUT_FIELD_DEFINITION | ARGUMENT_DEFINITION\n\ninput UserInput {\n  name: String!\n  age: Int @validation(min: 0, max: 120)\n}\n\n// Usage in your app:\nimport { UserInput } from './schemas';\nconst result = UserInput.safeParse({ name: 'John', age: 30 });\nif (!result.success) console.error(result.error.flatten());","lang":"typescript","description":"Generates Zod schemas from GraphQL input types using codegen.yml configuration with optional directives for validation."},"warnings":[{"fix":"Use only for input validation. For output schemas, consider other tools.","message":"Plugin only works with GraphQL input types and arguments; does not generate schemas for output types.","severity":"breaking","affected_versions":"<=1.10.6"},{"fix":"Set onlyWithValidation: true only if you intend to skip inputs without @validation directives.","message":"The 'onlyWithValidation' option defaults to false; if set to true, schemas for inputs without @validation directives are skipped.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Define zodSchemasMap for custom scalars, e.g., EmailAddress: z.string().email()","message":"Custom scalar mapping requires 'zodSchemasMap' config; otherwise unknown scalars default to z.any() and may cause type mismatches.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Include the directive definition in your schema file used as codegen schema.","message":"Directive @validation must be defined in the schema for advanced validation to work; introspection does not include directives.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.10.6':17 'activ':20 'allow':23 'code':58 'codegen':2,6 'custom':51 'defin':26 'develop':24 'differenti':40 'direct':31 'ecosystem':60 'field':37 'generat':9,59 'graphql':1,5,13,30,42,57 'input':14 'integr':55 'javascript':61 'keep':41 'key':39 'maintain':21 'map':53 'plugin':7 'reli':34 'requir':36 'rule':28 'scalar':52 'schema':11 'singl':44 'sourc':45 'stabl':19 'support':50 'truth':47 'type':15 'valid':27,32,49 'version':16 'via':29 'zod':3,10","created_at":"2026-06-07T16:53:32.306783+00:00","updated_at":"2026-06-07T16:53:32.306783+00:00","problems":[{"fix":"Add the directive definition from the documentation to your schema file.","cause":"Missing @validation directive definition in the schema file.","error":"Cannot read properties of undefined (reading 'directives')"},{"fix":"Add @validation directive to the input or set onlyWithValidation: false.","cause":"onlyWithValidation: true but input does not have @validation directive.","error":"Expected a valid Zod schema but received a GraphQL input type without generated schema"},{"fix":"Add zodSchemasMap: { EmailAddress: 'z.string().email()' } in codegen.yml plugin config.","cause":"Scalar not mapped in zodSchemasMap.","error":"Unknown scalar 'EmailAddress' - generated as z.any()"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/withshepherd/graphql-codegen-zod","github":"https://github.com/withshepherd/graphql-codegen-zod","docs":null,"changelog":null,"pypi":null,"npm":"graphql-codegen-zod","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops","testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}