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

Ability to not generate certain routers #37

Closed
bring-shrubbery opened this issue Oct 6, 2022 · 4 comments · Fixed by #45
Closed

Ability to not generate certain routers #37

bring-shrubbery opened this issue Oct 6, 2022 · 4 comments · Fixed by #45
Assignees
Labels
enhancement New feature or request

Comments

@bring-shrubbery
Copy link

Problem

Some of the models created in Prisma schema are not meant to be touched by the frontend at all. As an example, VerificationToken from the NextAuth is not something I want to be able to interact with from the client-side - I want to leave it to NextAuth to deal with it.

Suggested solution

It would be great to be able to disable the generation of a router for the Prisma model by using a simple comment, something like following:

// @trpc-ignore
model VerificationToken {
  ...
}

I understand that it's not as straightforward as just ignoring the model, since other models might reference the ignored one. In this case, the other model's router should also not include the ignored model, so the property that references it should be removed.

Alternatives

If this feature already exists, would be nice to have it documented in README

@omar-dulaimi omar-dulaimi added the enhancement New feature or request label Oct 14, 2022
@omar-dulaimi omar-dulaimi self-assigned this Nov 18, 2022
@omar-dulaimi omar-dulaimi added this to To do in Issues Progress Tracking via automation Nov 18, 2022
@omar-dulaimi omar-dulaimi moved this from To do to In progress in Issues Progress Tracking Nov 18, 2022
@omar-dulaimi omar-dulaimi linked a pull request Nov 18, 2022 that will close this issue
@omar-dulaimi
Copy link
Owner

omar-dulaimi commented Nov 18, 2022

@bring-shrubbery @kristinlindquist Please check these two PRS and let me know if it works fine for you.
(tRPC Generator): #45
(Zod Generator): omar-dulaimi/prisma-zod-generator#42

CC: @Shahidul1004 @BitPhoenix

@omar-dulaimi
Copy link
Owner

omar-dulaimi commented Nov 18, 2022

Hiding models will look like this in your Prisma schema:

/// @@Gen.model(hide: true)
model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
}

@bring-shrubbery
Copy link
Author

bring-shrubbery commented Nov 26, 2022

@omar-dulaimi Seems to work for me. Maybe it would also be useful to add a relation to the hidden "Map" model in the example schema? This would test the hiding of the parameter when it's referenced from somewhere? Maybe something like this:

model Post {
  id        Int      @id @default(autoincrement())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  title     String
  content   String?
  published Boolean  @default(false)
  viewCount Int      @default(0)
  author    User?    @relation(fields: [authorId], references: [id])
  authorId  Int?
  likes     BigInt

  maps Map[]
}

/// @@tRPCGen.model(hide: true)
model Map {
  key    String @id
  value  String
  Post   Post?  @relation(fields: [postId], references: [id])
  postId Int?
}

Issues Progress Tracking automation moved this from In progress to Done Nov 28, 2022
@omar-dulaimi
Copy link
Owner

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
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants