Sharing logic between queries and mutations
hello, I'm having an hard time calling an
internalQuery
from a mutation
action. Is this possibile?3 Replies
You can call JS/TS functions from mutations and queries:
https://docs.convex.dev/typescript#type-annotating-server-side-helpers
There's no point in calling a query from a mutation, since a mutation can do everything a query can do.
TypeScript | Convex Developer Hub
Move faster with end-to-end type safety.
https://docs.convex.dev/production/best-practices#use-helper-functions-to-write-shared-code for more examples
Best Practices | Convex Developer Hub
Here's a collection of our recommendations on how best to use Convex to build
Thanks,I created a "helpers.ts" file where I write reusable functions, But is creating a helper file where I store all the functions considered a safe practice?
For example, as long as I check if the user is authorized to check the functions before they get called in the real functions (query, action, mutation, etc) it should be safe right?
There's no way one could run this functions directly?
