Skip to content

Maybe<T> not undefined for optional strings using z.string().nullish() with zod #1086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ChrisEnglert opened this issue May 21, 2025 · 0 comments
Labels
good first issue Good for newcomers

Comments

@ChrisEnglert
Copy link

ChrisEnglert commented May 21, 2025

Hello, thanks for this codegen plugin!
However, I seem to have a problem with zod:

Given the GraphQL Schema e.g.:

input AppointmentInput {
	description: String
...

(Optional String description)

The generated Schema is:

export function AppointmentInputSchema(): z.ZodObject<Properties<AppointmentInput>> {
  return z.object({
    description: z.string().nullish(),

this is giving me an error saying:

Type 'undefined' is not assignable to type 'InputMaybe'

The error goes away if I manually change it to:

  ...
  description: z.string().nullable(),
   ...

( nullable instead of nullish)

My config is:

      config: {
        importFrom: "./schema",
        withObjectType: true,
        useTypeImports: true,
        schema: "zod",
        strictScalars: true,
       }

Using:
"graphql-codegen-typescript-validation-schema": "^0.17.1"
"zod": "^3.24.4"

@github-actions github-actions bot added the good first issue Good for newcomers label May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant