Does anyone have a good solution for performing va...
# prisma-whats-new
a
Does anyone have a good solution for performing validation on a mutation that doesn't lie client side?
s
@amann What kind of validation do you need to do?
a
I want to check if a users email address in another type exists before I store to the DB
And in this case the uniqueness constraint doesn't solve that problem
w
Could you store the users email address in its own model, with a uniqueness constraint, which both of your models then relate to?
s
@wallslide - this is our recommended approach. We are working on ways to add custom constraints, but in this case I actually think a shared model is a cleaner approach. Thank!
a
Fair, but other things like validating that an email is actually an email server side
Is there currently no possible way to do this?
s
Good question - Currently there are two approaches you might consider if it is critical to validate data on the server. In both cases you should also validate data on the client to ensure a good user experience. 1) Involves accepting invalid input and then running a mutation callback to verify the data and take action if it is invalid. This could be deleting the noe, flagging the node or starting some out-of-band process. 2) is to set up two models. One is the input model, and the mutation callback would validate input data and create a node for the second “real” model
Both approaches are more complicated than they should be and we are working on addressing this.
a
Yeah those we're the two approaches I've been taking and they just felt clunky - was wondering if someone else was using something that I didn't think of
But glad to hear that you guys are working on this!