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
I need some generic validator for these types (as I cannot change every validator if I make a schema change):
And the same for user
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)
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
Ah, gotcha
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
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
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()
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()
.ok