Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support extendedWhereUnique preview feature #59

Closed
mubaidr opened this issue Dec 4, 2022 · 12 comments · Fixed by #68
Closed

Support extendedWhereUnique preview feature #59

mubaidr opened this issue Dec 4, 2022 · 12 comments · Fixed by #68
Labels
enhancement New feature or request

Comments

@mubaidr
Copy link

mubaidr commented Dec 4, 2022

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

  • OS: Linux ()
  • Database: PostgreSQL
  • Node.js version: v18.4.0

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
Copy link
Owner

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

@mubaidr
Copy link
Author

mubaidr commented Dec 22, 2022

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
Copy link
Owner

Could you share a sample schema that produce this issue?

@mubaidr
Copy link
Author

mubaidr commented Dec 25, 2022

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
Copy link
Owner

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
Copy link
Owner

@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
Copy link
Author

mubaidr commented Dec 31, 2022

Sorry for the delayed response.

  • I am trying to use generated zod schema to validate input in TRPC procedures.

  • Here is sample (part of whole schema, can't share complete due to licence issues) prisma schema:

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.

  • Open CityWhereUniqueInput.schema.ts in ./generated/zod/schemas/object, it will show error as shown in above screenshot, please.

@omar-dulaimi omar-dulaimi added the bug Something isn't working label Dec 31, 2022
@omar-dulaimi
Copy link
Owner

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

@omar-dulaimi omar-dulaimi changed the title Invalid code generation for WhereUniqueInputObjectSchema Support extendedWhereUnique preview feature Dec 31, 2022
@mubaidr
Copy link
Author

mubaidr commented Dec 31, 2022

I did test it by disabling this preview feature here: #59 (comment)

But maybe I have missed something.

P. S. Thanks for your awesome work.

@omar-dulaimi omar-dulaimi added enhancement New feature or request and removed bug Something isn't working labels Dec 31, 2022
@omar-dulaimi omar-dulaimi linked a pull request Dec 31, 2022 that will close this issue
@omar-dulaimi
Copy link
Owner

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
Copy link
Author

mubaidr commented Dec 31, 2022

Sure, I will try and report here. 👍🏼

@mubaidr
Copy link
Author

mubaidr commented Jan 1, 2023

Yes, Its working good now! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants