Skip to content

Commit

Permalink
fix(zod): generate optional field as z.optional() rather than `z.nu…
Browse files Browse the repository at this point in the history
…llish()` to be consistent with Prisma's typing
  • Loading branch information
ymc9 committed May 9, 2024
1 parent 5806a4d commit 17e91fe
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/schema/src/plugins/zod/utils/schema-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ export function makeFieldSchema(field: DataModelField) {
// field uses `auth()` in `@default()`, this was transformed into a pseudo default
// value, while compiling to zod we should turn it into an optional field instead
// of `.default()`
schema += '.nullish()';
schema += '.optional()';
} else {
const schemaDefault = getFieldSchemaDefault(field);
if (schemaDefault !== undefined) {
schema += `.default(${schemaDefault})`;
}

if (field.type.optional) {
schema += '.nullish()';
schema += '.optional()';
}
}

Expand Down

0 comments on commit 17e91fe

Please sign in to comment.