get-convex / convex-js

TypeScript/JavaScript client library for Convex
https://docs.convex.dev
Apache License 2.0
106 stars 12 forks source link

Mutation: Prevent empty string in args #4

Closed mfakhrys closed 1 year ago

mfakhrys commented 1 year ago

Hello, is there any way to prevent an empty string when we call a mutation?

In my case, I have a users table, and in the "create" mutation I accept "name" args, currently empty string is accepted.

Is there any built in method? Or do I need to reject it in handler?

Thanks in advance

xixixao commented 1 year ago

Hey @mfakhrys, you can reject the invalid value in the handler. This gives you the power to enforce any rule you'd like, arbitrarily complex (you have a whole Turing-complete language at your disposal).

We might consider more granular validators in the future.