Code-Hex/graphql-codegen-typescript-validation-schema

Allow transform after .default in zod

MaLiN2223 opened this issue · 1 comments

Currently, due to limitation of the zod framework, all default properties become nullable which causes an issue for us. The apparent solution is to add a transform call after the .default(, e.g. z.boolean().default(false).transform(option.fromNullable)

I know that I can do
scalarSchemas: { Boolean: "z.boolean().transform(option.fromNullable)", },
but this applies the transformation before .default

Looking at the code (index.ts for zod), I can see that the default is hardcoded to be the last one.

Would it be possible to configure the plugin to generate something after .default?

I ended up with a custom plugin.