Skip to content

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

Closed

Description

@ChrisEnglert

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"

Activity

  1. Code-Hex commented on Sep 23, 2025

    @Code-Hex
    Owner

    @ChrisEnglert Sorry for the late reply. I just released 0.18.0, so please try it. If you can still reproduce the issue, it would be very helpful if you could provide an environment where you can reproduce it, such as on codesandbox.

  2. supernaut commented on Oct 8, 2025

    @supernaut

    I have the same issue in version 0.18.1. Replacing .nullish with .nullable fixes the issue.

  3. flesler commented on Oct 22, 2025

    @flesler

    IMO there should be a setting that defaults to .nullish() and can be overriden, just like custom scalars. For those that need .optional() or .nullable() (depending on the case). Right now I'm handling in a post-processing script, which is not ideal

  4. Code-Hex commented on Apr 25, 2026

    @Code-Hex
    Owner

    Fixed in #1423. Zod nullable field generation is now configurable, so projects whose Maybe type does not include undefined can opt into nullable instead of nullish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions