Skip to content

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

Open
@ChrisEnglert

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions