EvaE
Convex Community10mo ago
45 replies
Eva

Why is calling Convex queries/mutations directly an anti-pattern?

I'm currently working through refactoring my Convex queries and mutations to allow upgrading to 1.21, which throws a type error when you call Convex functions from other Convex functions.

The docs recommend relocating your functions into a model/ directory, and then importing and calling those functions from your Convex mutations and queries.

I have a few questions:

1. Why is calling Convex functions from other functions an anti-pattern, specifically?
2. The examples in the docs take the logic from the original query/mutation and relocate it to a new function in a directory called model/, and then import and call that function from the original mutation/query. I don't fully understand the rationale behind this, since now there are two separate files with similar/identical function names, and two places to test instead of one.
3. For maintainability, is the recommendation to relocate all query and mutation logic into a separate function within model/? My first intuition was to only relocate the shared logic, but the docs seem to suggest otherwise?
This is a list of best practices and common anti-patterns around using Convex.
Best Practices | Convex Developer Hub
Was this page helpful?