Hi guys! I need to implement validations on mutati...
# orm-help
a
Hi guys! I need to implement validations on mutations in Prisma. The doc suggests to check values directly in the resolver, which is ok for me, but what about the checks on the relations? For example, take
Post
and
Tag
, let's say that in an update mutation on
Post
I need to create a
Tag
, how can validate the new tag?
n
what stops you from validating the tag?
a
hi nilan, in the
Post
mutation, the
Tag
(beign a relation) is not a plain object, but has the input structure like
connect: {id: "xyz"}
, same for create, disconnect and so on. So it's not as straightforward as validating the main object. Moreover I have nested relations, so I cannot check them one by one in this way. I would expect the inner relation to call my
Tag
mutation resolver and do there all the validations, but instead it is called the main mutation
context.db.mutation.createTag
, so I can't do checks in the middle
I know exists this proposal for DB constraints
<https://github.com/graphcool/prisma/issues/728>
that would be perfect, but it's a WIP, so how do you suggest I should move in the meantime?
n
You can define the input fields yourself, so instead of
connect: {id: "xyz"}
you could define an input field
tagId: "xyz"
which you then can validate in your own resolver
a
yes, it could be a viable solution, even if we will lose a bit the advantage of using Prisma and its code generation. Not asking for ETA, but you know if someone is actively working on the issue 728?