Doc validator
How would I specify a doc type for the argument validator of a convex action? E.g. something along the lines of
12 Replies
Hey @wjarjoui, we don't have this. Usually you either want to send in the value required to create or update a document, or you'd send in an ID or list of IDs, and load the documents inside the function. This ensures that they are the latest versions of the documents.
What's your use case?
This article might be helpful:
https://stack.convex.dev/types-cookbook
it shows how to reuse validators between schema and args
Types and Validators in TypeScript: A Convex Cookbook
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 ...
I have a calling action that already does this query to get the document, so I am trying to avoid doing it again in the called action. Although I see your point, and from prior understanding those queries end up being very cheap so perhaps best to just query again.
Yup, presumably you're scheduling the called action, so the documents could change between the scheduling and when the called action runs.
correct. I hadn't thought about that because they almost never change, but I like this safetyguard.
On another note, would be great if there were easier ways to specify schemas for the v.object type, e.g. if I can pass a type instead of a schema
Agreed, being able to work with TypeScript types and have them compile to JS validators would be really nice (both for argument and schema validation).
On another note, I am trying to load a json object from a file in my convex module:
and I get the error:
The flag
resolveJsonModule
is already in my project's ts.config, do I need to add it to convex.json too?
Trying to find a page for all the convex.json options, if that's available please point me to itYou might need a Node action for this, I'm not sure our esbuild setup allows loading json files.
It's actually running OK just the typescript is complaining. Either way, is there an outline of the full config options for convex.json?
I've already made a helper for making these objects 🎉 . Article just went out yesterday: https://stack.convex.dev/argument-validation-without-repetition
Argument Validation without Repetition
In the first post in this series, the Types and Validators cookbook, we shared several basic patterns & bes...
There are only two options:
https://docs.convex.dev/production/project-configuration#changing-the-convex-folder-name-or-location
and
https://docs.convex.dev/functions/bundling#specifying-external-packages
We should have a doc page that lists them together though, that's good feedback.
Bundling | Convex Developer Hub
Bundling is the process of gathering, optimizing and transpiling the JS/TS
Project Configuration | Convex Developer Hub
Local development
(so to your question there's no
resolveJsonModule
in convex.json - if its TypeScript complaining make sure you're changing the right tsconfig.json, our templates usually have two, one inside the convex/ folder)I made a thread in #stack for the new article: https://discord.com/channels/1019350475847499849/1195812243892355192