Pass whole db entry into action

Hi, I want to pass a whole user object and message object into my action. How can I do that? I mean: How do I write the args for that?
9 Replies
FleetAdmiralJakob 🗕 🗗 🗙
I need some generic validator for these types (as I cannot change every validator if I make a schema change):
PromiseEntWriter<GenericEntsDataModel, "messages">
PromiseEntWriter<GenericEntsDataModel, "messages">
(typeof entDefinitions)["messages"]["document"]
(typeof entDefinitions)["messages"]["document"]
And the same for user
erquhart
erquhart•7mo ago
Not sure how this translates to Ents, but there's a stack article that might help: https://stack.convex.dev/types-cookbook#keep-validators-from-going-stale (Link is to a specific paragaraph that's relevant)
FleetAdmiralJakob 🗕 🗗 🗙
It not really works for ents because I'm using the .field() for the schema definitions and not defining everything in a single object because I need stuff like default, unique and stuff
erquhart
erquhart•7mo ago
Ah, gotcha
Michal Srb
Michal Srb•7mo ago
Actions cannot read from teh DB, so unique, default etc. doesn't apply. In general the typical access patterns are: Client calls mutation Mutations writes and loads some data Mutation schedules an action (passing in IDs or plain JS object data) Action performs third-party API calls Action calls a mutation Or Client calls an action Action calls a query to load data Query returns IDs or plain JS object data Action performs third-party API calls Action calls a mutation
Michal Srb
Michal Srb•7mo ago
The tutorial demonstrates this too: https://docs.convex.dev/tutorial/actions
3: The platform in action | Convex Developer Hub
Learn about harnessing the broader backend platform capabilities to
FleetAdmiralJakob 🗕 🗗 🗙
I know that actions cannot read from the db. that's why I want to pass the whole db entry that was queried in the mutation to the action and that without changing the validators of the action if changing the schema. the problem is that I cannot use the validator of the schema in the args of the action because they are defined with the field()
Michal Srb
Michal Srb•7mo ago
Yeah, we are looking into allow you to get the field validators out of the schema / table definition. For now you'll have to duplicate in the case of Ents when using .field().