saito200S
Convex Community2y ago
1 reply
saito200

Validator from schema, including internal fields?

I'm passing full DB records to one of my actions and I'm trying to build the validator
After some tinkering it looks like this:

export const myAction = internalAction({
  args: {
    idea: v.object({ ...myValidator, _id: v.id("myTable") })
  },


I am exporting the validator from the schema similar as described here https://stack.convex.dev/types-cookbook

The fact that I have to add the _id manually feels a bit awkward to me, but I need the id to be used as a foreign key

Am I doing something weird? Is this simply ok? (the action uses some of the fields of the record to create a record for a different table)

What I started looking for originally was like a built-in validator that can be extracted from the schema or somewhere else, similar as you can get the DB record type with Doc<"myTable"> but the equivalent for validators, including internal fields
It can be tough to wrangle types to behave how you want them to. Thankfully, Convex was designed to make the experience with types perfect. Learn why ...
Types and Validators in TypeScript: A Convex Cookbook
Was this page helpful?