typegraphql-prisma icon indicating copy to clipboard operation
typegraphql-prisma copied to clipboard

ability to omit compound unique from typegraphql types

Open shawnjones253 opened this issue 1 year ago • 5 comments

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 ???

shawnjones253 avatar Dec 21 '23 21:12 shawnjones253

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

MichalLytek avatar Dec 21 '23 21:12 MichalLytek

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 avatar Dec 21 '23 21:12 shawnjones253

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 avatar Dec 21 '23 21:12 shawnjones253

@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 avatar Dec 21 '23 22:12 shawnjones253

@MichalLytek see clarification above

shawnjones253 avatar Jan 10 '24 08:01 shawnjones253