chrishoermann / zod-prisma-types

Generator creates zod types for your prisma models with advanced validation
Other
578 stars 43 forks source link

[BUG] Duplicate schema names exported #205

Open brianbolnick opened 7 months ago

brianbolnick commented 7 months ago

Describe the bug Hi! Love the concept behind this repo. Just ran my first generate and it has a duplicate schema exported. I've tried with both single and multi-file outputs. The multi-file has seemed to shed some possible light. Wondering if it has anything to do with a double export 🤷:

export const OutcomeUpdateArgsSchema: z.ZodType<Prisma.OutcomeUpdateArgs> = z.object({
  select: OutcomeSelectSchema.optional(),
  include: OutcomeIncludeSchema.optional(),
  data: z.union([ OutcomeUpdateInputSchema,OutcomeUncheckedUpdateInputSchema ]),
  where: OutcomeWhereUniqueInputSchema,
}).strict() ;

export default OutcomeUpdateArgsSchema;

Which leads to the index file including both of these:

export { OutcomeUpdateArgsSchema } from './OutcomeUpdateArgsSchema';
export { OutcomeUpdateArgsSchema } from './OutcomeUpdateArgsSchema';

It only happened with this one model, so it very likely could be an issue on our end. Here's the schema itself:


model OutcomeUpdate {
  id      String @id @default(cuid())
  changes Json

  faculty   Faculty? @relation(fields: [facultyId], references: [id])
  facultyId String?
  outcome   Outcome  @relation(fields: [outcomeId], references: [id], onDelete: Cascade, onUpdate: Cascade)
  outcomeId String
  student   Student? @relation(fields: [studentId], references: [id])
  studentId String?

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

Screenshots N/A

Package versions (please complete the following information):

Additional context N/A

chrishoermann commented 7 months ago

@brianbolnick thanks for repoting the issue, can you please provide a complete schema if possible so i can run it on my end?

chrishoermann commented 7 months ago

@brianbolnick I changed the generation of imports in barrel files to use Set instead of array to prevent duplicate imports. Can you please check if this solves your problem or if it generates problems in other places of the schemas.

Please also be aware that the latest version is targeted for the use with prisma 5.2.x so maybe a this bug could be a result of this version discrepancy.

Also zod 3.21.4 might make problems because of a type error in the schemas that happens in zod > 3.21.1 - a flag to use type assertion - useTypeAssertions = true in generator config - is implemented that can circumvent this bug but that also overrides the type system, so please use at your own risk

brianbolnick commented 7 months ago

Looks like it is still occurring with the current versions of prisma and zod, unfortunately. I'll try to revert back where possible, but may need to figure something else out until it's all fully supported :)

chrishoermann commented 7 months ago

Well, that's odd. Is it possible to provide the full schema so I can reproduce the issue on my end?

brianbolnick commented 7 months ago

Unfortunately it's a private repo and I can't share it :/ It's only affecting one model, so I'll see if I can put together a replica of it and any relations to it that you could use later.