omar-dulaimi / prisma-trpc-generator

Prisma 2+ generator to emit fully implemented tRPC routers
MIT License
675 stars 34 forks source link

Add config option to enable specific model actions #68

Closed lottamus closed 1 year ago

lottamus commented 1 year ago

Description

Currently, we're generating a route for every possible model action, sometimes resulting in unused code.

This PR adds an optional config to enable specific model actions.

Example Input:

generator trpc {
  provider           = "prisma-trpc-generator"
  generateModelActions = "create,delete,findFirst,findMany,findUnique,update,upsert"
}

Example output:

image

References

It would be much nicer to allow providing an array for generateModelActions, however it seems this currently is not possible: https://github.com/prisma/prisma/issues/9511

Other

We could also expose this functionality at the model level too

/// @@Gen.model(actions: [create,delete,findFirst,findMany,findUnique,update,upsert])
model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
  books Book[]
}
omar-dulaimi commented 1 year ago

This is a cool addition. Thanks for your work on this and other PRs

omar-dulaimi commented 1 year ago

We should also pass these options values to Zod generator under the hood so it could skip any extra schemas from being generated. That is for a future thing of course.

omar-dulaimi commented 1 year ago

Released in https://github.com/omar-dulaimi/prisma-trpc-generator/releases/tag/1.1.0