How can I validate an update input type? #101
-
Hi, given the following Prisma schema: model User {
...
email String @unique
...
} I was able to easily add a validation rule to the email property by using this type enhancer: const userInputTypesEnhancer: InputTypeConfig<"UserCreateInput"> = {
fields: {
email: [IsEmail()],
},
} Now I would like to be able to add a similar validation rule to the class UserUpdateInput {
...
email?: StringFieldUpdateOperationsInput | undefined;
...
} where class StringFieldUpdateOperationsInput {
set?: string | undefined;
} Is there an easy way I can add a type enhancer only to the const userInputTypesEnhancer: InputTypeConfig<"UserUpdateInput"> = {
fields: {
email: [IsEmail()],
},
} then what I am effectively decorating/validating is Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
There's no solution for that and I can't imagine any for now. That two approaches just doesn't match together. |
Beta Was this translation helpful? Give feedback.
typegraphql-prisma
was always meant to be a source code generator, not a "DB into GraphQL API" converter/layer.Adding decorators to types is just a workaround for those who want to add validation/other stuff without ejecting from the generator flow.
There's no solution for that and I can't imagine any for now. That two approaches just doesn't match together.
With code first approach #9 you would need to write the input classes by yourself, in order to modify them and add a decorator.