prisma-nestjs-graphql
prisma-nestjs-graphql copied to clipboard
custom import
Hi, I have a question. I want to print a constant or dynamic message in the message option in class-validator, but I can't do my import statement at the top. Is there any way to solve this?
generator graphqlmodel {
provider = "prisma-nestjs-graphql"
output = "../model/src/lib/@generated"
reExport = All
fields_ErrorMessage_from = "@temp/constants"
fields_ErrorMessage_defaultImport = "{ ErrorMessage }"
fields_ErrorMessage_input = true
fields_ErrorMessage_output = true
fields_Validator_from = "class-validator"
fields_Validator_namedImport = true
fields_Validator_input = true
fields_Validator_output = true
}
model User {
/// @Validator.IsNotEmpty()
/// @Validator.IsString()
/// @Validator.MaxLength(191)
id String @id @default(cuid())
/// @Validator.IsEmail({}, { message: ErrorMessage.MSG_EMAIL_RULES_VIOLATION, }, )
/// @Validator.IsNotEmpty({ message: ErrorMessage.MSG_NOT_FOUND_EMAIL, } )
/// @Validator.MaxLength(256)
email String? @unique @db.VarChar(256)
}
import { ErrorMessage } from '@temp/constants';
dto file doesn't have that import
No, it is not possible to have variables/dynamic values in directive comments.
Have you tried people solutions for class-validator?
- https://github.com/typestack/class-validator/issues/169
- https://github.com/kasir-barati/class-validator-translator-middleware