Kerem Kazan
05/12/2021, 3:26 PMmodel Member {
id Int @id @default(autoincrement())
email Email
}
the Email
type would be coming from typescript. If modifying the schema like above is not possible/recommended, is it at least possible to have this type appear on the generated client types? i’d want all prisma methods on the Member
type to expect the email field to be of type Email
, not just string
Robert Witchell
05/12/2021, 10:50 PMKerem Kazan
05/14/2021, 5:33 PMnewtype-ts
to create types for validated domain values. in this case, any variable of type Email
will be a validated string that is structured as an email. If possible, i’d like to plug that into the generated types for my prisma models where it’ll be impossible to pass a simple string for the email field. This way whenever I’m interacting with my db models (either reading or writing), i will have the guarantee that it’ll be impossible to write a non-verified email string. does that make sense?Kerem Kazan
05/14/2021, 5:35 PMEmail
as opposed to just string
. This will let me write my code in a way that leverages the type system and help me understand which values are validated and not.Robert Witchell
05/15/2021, 4:56 AMemail string
Not sure how you can handle this in your resolver, as it's returning a json array, but you could resolve the email property like this, which would be similar to a datetime being resolved (i think) email: (parent, args, context, info) { return new YourEmailObjectConstructor(parent.email) }