Closed alainfonhof closed 2 years ago
Please check UserCreateInput
type from Prisma Client, e.g. when you call prisma.user.create()
.
typegraphql-prisma
only translates Prisma DMMF into classes, it doesn't add or hide properties when it's autoincrement or uuid.
Maybe I don't understand it correctly but when I have the following prisma.schema
:
generator typegraphql {
provider = "typegraphql-prisma"
output = "../prisma/generated/type-graphql"
}
model UserA {
id Int @id @default(autoincrement())
label String
}
model UserB {
id String @id @default(uuid())
label String
}
After running npx prisma generate
it results in the following types in the prisma-client
:
export type UserACreateInput = {
label: string
}
export type UserACreateManyInput = {
id?: number
label: string
}
export type UserBCreateInput = {
id?: string
label: string
}
export type UserBCreateManyInput = {
id?: string
label: string
}
The type UserACreateInput
has id
omitted while for UserB this isn't the case, right? It also seems to have inconsistency between UserACreateInput
and UserACreateManyInput
.
It's a correct behaviour for normal create and create many.
But yes, it looks like a Prisma issue that id still exist for the default uuid id string field. Please report on theirs repo.
What would be the best approach to hide the id
field from certain input types like UserCreateManyInput
, UserCreateInput
and UserUpdateInput
? The doc line /// @TypeGraphQL.omit(input: true)
will not work because it also omits the id
field from UserWhereUniqueInput
.
I have been looking into Additional decorators for CRUD resolvers and Prisma classes and fields and Omit but it is not clear to me if this is the right approach.
How would I go about hiding the id
field for certain input types without editing the generated type-graphl
?
It's not possible for now.
@alainfonhof Have you reported the bug with id field in create input on Prisma repo?
hey!! any updates on this?
Describe the Bug When defining a model:
This will result in:
While in the example in the docs Hiding Prisma model field in GraphQL schema it shows the id field is omitted. When defining a User model with
id Int @id @default(autoincrement())
it does seem to result in the expected behaviour.Environment:
typegraphql-prisma
version 0.16.0