MichalLytek / typegraphql-prisma

Prisma generator to emit TypeGraphQL types and CRUD resolvers from your Prisma schema

Home Page:https://prisma.typegraphql.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ability to omit compound unique from typegraphql types

shawnjones253 opened this issue · 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
???

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

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

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?

@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

@MichalLytek see clarification above