MichalLytek / typegraphql-prisma

Prisma generator to emit TypeGraphQL types and CRUD resolvers from your Prisma schema
https://prisma.typegraphql.com
MIT License
891 stars 113 forks source link

ability to omit compound unique from typegraphql types #431

Open shawnjones253 opened 11 months ago

shawnjones253 commented 11 months ago

Is your feature request related to a problem? Please describe. assume you have this model:

model MyModel {
  id String
  organizationId String

  @@unique([id, organizationId])
}

there doesn't seem to be a way to hide the generated id_organizationId field in typegraphql-generated types (if there is please let me know) :)

Describe the solution you'd like The clearest way I can think of is to make /// @TypeGraphQL.omit(input: true) work for @@unique

Describe alternatives you've considered ???

MichalLytek commented 11 months ago

You need this field in inputs in order to properly find unique records in db via graphql api.

shawnjones253 commented 11 months ago

You need this field in inputs in order to properly find unique records in db via graphql api.

sorry, my example should have marked the id as @unique as well

in my case, i want to expose id as the only unique the caller is allowed to use for input, despite prisma allowing id | id_organizationId

shawnjones253 commented 11 months ago

to make this more clear, i can hide regular @uniques but not @@uniques -- as long as i leave at least one of the regular @uniques available to the caller that should still work with findUnique right?

shawnjones253 commented 11 months ago

@MichalLytek -- here's a clearer example:

model MyModel {
  id String @unique
  /// @TypeGraphQL.omit(output: true, input: true)
  organizationId String

  @@unique([id, organizationId])
}

this currently generates:

export declare class MyModelWhereUniqueInput {
    id?: string | undefined;
    id_organizationId?: MyModelIdOrganizationIdCompoundUniqueInput | undefined;
}

but what i want to generate instead is:

export declare class MyModelWhereUniqueInput {
    id?: string | undefined;
}

that still has at least one unique field (id) so it would still be usable as input to findUnique

for context, organizationId should be opaque to end users in my application, i'd like to use it in a prisma context without exposing it via the api / typegraphql types

shawnjones253 commented 10 months ago

@MichalLytek see clarification above