omar-dulaimi / prisma-zod-generator

Prisma 2+ generator to emit Zod schemas from your Prisma schema
MIT License
513 stars 45 forks source link

Support extendedWhereUnique preview feature #59

Closed mubaidr closed 1 year ago

mubaidr commented 1 year ago

Bug description

Generated schema for ModelVacancyWhereUniqueInputObjectSchema is invalid.

How to reproduce

  1. Add latest prisma and generator version
  2. run prisma generate
  3. Inspect ModelVacancyWhereUniqueInputObjectSchema file for any model
  4. See error

Screenshot_20221204_221504

Expected behavior

Generated schema should not contain any errors.

Prisma information

generator zod {
  provider          = "prisma-zod-generator"
  output            = "./generated/zod"
  isGenerateSelect  = true
  isGenerateInclude = true
}

Environment & setup

Prisma Version

prisma                  : 4.7.1
@prisma/client          : 4.7.1
Current platform        : debian-openssl-3.0.x
Query Engine (Node-API) : libquery-engine 272861e07ab64f234d3ffc4094e32bd61775599c (at node_modules/.pnpm/@prisma+engines@4.7.1/node_modules/@prisma/engines/libquery_engine-debian-openssl-3.0.x.so.node)
Migration Engine        : migration-engine-cli 272861e07ab64f234d3ffc4094e32bd61775599c (at node_modules/.pnpm/@prisma+engines@4.7.1/node_modules/@prisma/engines/migration-engine-debian-openssl-3.0.x)
Introspection Engine    : introspection-core 272861e07ab64f234d3ffc4094e32bd61775599c (at node_modules/.pnpm/@prisma+engines@4.7.1/node_modules/@prisma/engines/introspection-engine-debian-openssl-3.0.x)
Format Binary           : prisma-fmt 272861e07ab64f234d3ffc4094e32bd61775599c (at node_modules/.pnpm/@prisma+engines@4.7.1/node_modules/@prisma/engines/prisma-fmt-debian-openssl-3.0.x)
Format Wasm             : @prisma/prisma-fmt-wasm 4.7.1-1.272861e07ab64f234d3ffc4094e32bd61775599c
Default Engines Hash    : 272861e07ab64f234d3ffc4094e32bd61775599c
Studio                  : 0.477.0
omar-dulaimi commented 1 year ago

This happens with tRPC v10, correct? If that was the case, then this should be resolved soon with the upgrade

mubaidr commented 1 year ago

No, I am using provider = "prisma-zod-generator" (but i think it will be same with that too as it has dependency n this package)

omar-dulaimi commented 1 year ago

Could you share a sample schema that produce this issue?

mubaidr commented 1 year ago

I think this issue could be related to previewFeature extendedWhereUnique, it still happens with latest version:

"prisma-zod-generator": "^0.8.6"

I will try and check if disabling it solves the issue.

Update: Just tested this, It still shows error

omar-dulaimi commented 1 year ago

I would appreciate it if you could share a schema that I could test on, so I could provide a fix for it

omar-dulaimi commented 1 year ago

@mubaidr Still waiting for more details. What are you trying to accomplish with this library?

What exactly is invalid to you? I see ZodObject in the screenshot, though the library generates ZodType only.

Please clarify what exactly is the problem and sample code is possible.

mubaidr commented 1 year ago

Sorry for the delayed response.

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["extendedWhereUnique", "filteredRelationCount", "orderByNulls"]
}

generator zod {
  provider          = "prisma-zod-generator"
  output            = "./generated/zod"
  isGenerateSelect  = false
  isGenerateInclude = false
}

// generator trpc {
//   provider           = "prisma-trpc-generator"
//   output             = "./generated/trpc"
//   contextPath        = "../context"
//   withMiddleware     = false
//   withShield         = false
//   isGenerateSelect   = false
//   isGenerateInclude  = false
// }

datasource db {
  provider     = "postgresql"
  url          = env("DATABASE_URL")
  relationMode = "foreignKeys"
}

model City {
  id              Int             @id @default(autoincrement())
  title           String          @unique
  createdAt       DateTime        @default(now()) @map("created_at") @db.Timestamptz
  updatedAt       DateTime        @default(now()) @map("updated_at") @db.Timestamptz
  venues          Venue[]

  @@map("city")
}

model Venue {
  id        Int      @id @default(autoincrement())
  code      String   @unique
  title     String   @unique
  address   String
  capacity  Int
  available Boolean  @default(true)
  cityId    Int      @map("city_id")
  createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz
  updatedAt DateTime @default(now()) @map("updated_at") @db.Timestamptz
  city      City     @relation(fields: [cityId], references: [id])

  @@map("venue")
}

After running generate command, zod schema is generated fine.

omar-dulaimi commented 1 year ago

Thank you for the details. I just confirmed the existence of the bug, will work on it as soon as possible.

mubaidr commented 1 year ago

I did test it by disabling this preview feature here: https://github.com/omar-dulaimi/prisma-zod-generator/issues/59#issuecomment-1364678233

But maybe I have missed something.

P. S. Thanks for your awesome work.

omar-dulaimi commented 1 year ago

Should be fixed in https://github.com/omar-dulaimi/prisma-zod-generator/releases/tag/0.8.10

Please confirm so I could update the tRPC generator as well

mubaidr commented 1 year ago

Sure, I will try and report here. 👍🏼

mubaidr commented 1 year ago

Yes, Its working good now! Thanks