ChrisC
Convex Community5mo ago
6 replies
Chris

Action Triggers from Convex Queries

I’m trying to figure out how to trigger an action from a query in Convex. Currently, the only option available is a mutation, which seems limiting. I understand why and I also understand that it's an anti pattern to even want to do it. That said, there are situations where you want to trigger an action when a user fetches data that isn't available. In those cases, you would want to initiate an action to fetch that data from an external service, populate it, and let sync do its thing.

The only alternative I can think of is to have the client code manage this. The client would run a query, and if it returns undefined or an empty dataset, it would then trigger a mutation or action to fetch the data. However, I’m concerned about this approach. What if the client code doesn't handle it properly? How can we ensure they do it correctly?
Was this page helpful?