Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Convex functions should not directly call other Convex functions." #395

Open
evadecker opened this issue Feb 12, 2025 · 0 comments
Open
Labels
bug Something isn't working
Milestone

Comments

@evadecker
Copy link
Member

evadecker commented Feb 12, 2025

Describe the bug
Currently we're directly calling Convex functions from other Convex functions. This produces warnings. Queries and mutations should be rewritten to avoid doing this, see: https://docs.convex.dev/understanding/best-practices#use-helper-functions-to-write-shared-code

Additionally:

We're notifying you about a Convex change which we've detected may affect your project(s).

In Convex 1.18, we introduced a warning when calling Convex queries, mutations, and actions directly as JavaScript functions. See https://news.convex.dev/announcing-convex-1-18/ for more details.

If you are calling such functions directly, it should appear as a console.warn log line coming from the function. In the near future, with Convex 1.21, the pattern is becoming a TypeScript error. That means npx convex dev and npx convex deploy (with typecheck enabled) will fail to push code if the pattern is used.

How to handle this error:

  1. Refactor the query, mutation, or action out as a helper function, then call that helper function directly. See https://docs.convex.dev/production/best-practices/#use-helper-functions-to-write-shared-code for more.
  2. Use ctx.runMutation, ctx.runQuery, or ctx.runAction instead of calling the function directly. This has more overhead (it's slower) but you gain isolation and atomicity because it runs as a subtransaction.

If you need to push without fixing the code, there are two quick options:

  1. Push code with the --typecheck disable flag, or cast to any to appease TypeScript. For [email protected] the function call will continue to work at runtime, even though it doesn't typecheck. In a future version it may stop working entirely.
  2. Delay upgrading to [email protected]. The pattern will continue to work in TypeScript and at runtime on 1.20 and below.
    Please reach out in Discord if you have any questions about this change or difficulty migrating. Alternatively, you can create a support ticket if you're a Convex Pro customer.

To Reproduce

  1. Run pnpm test
  2. Observe Convex warnings.

Expected behavior
Convex functions are not called directly from other Convex functions. There are no warnings.

Screenshots
Image

Additional context
We may need to create helper functions to manage shared behavior.

@evadecker evadecker added the bug Something isn't working label Feb 12, 2025
@evadecker evadecker added this to the Namesake v1.0 milestone Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant