CustomFunctions, vitest and multiple query call in a query
Hi everyone,
I'm struggling on a test. Vitest throw an error as below :
❯ Module.checkIfAuthorizedToCreateObject convex/validator.ts:9:15
7| ctx: GenericMutationCtx<DataModel>
8| ) => {
9| const sub = await ctx.runQuery(api.subscriptions.getSubscriptionInformation)
| ^
{
stack: 'Error: \n' +
' at performAsyncSyscall \n' +
' at runUdf \n' +
It's a query which is called inside a query (customQuery). I don't understand why, there are some limitations with vitest when we use custom functions or when we call queries in a query ?
thank you7 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
can you provide more of your code? i tried to repro, but the test passes for me.
I notice you're using
ctx.runQuery
from a query, which has unnecessary overhead. We recommend using functions instead https://docs.convex.dev/production/best-practices/#use-helper-functions-to-write-shared-codeBest Practices | Convex Developer Hub
Here's a collection of our recommendations on how best to use Convex to build
Hi @lee , very good thanks. I change my code as explained in the practices page and it looks good. The test still failed but for another reason (sharedComponent not registered).
Thanks for your help 🙂
ooh nice! now i'm wondering if the sharedComponent not being registered was throwing an error which was getting converted into the opaque
Error
message you were seeing. ctx.runQuery
in convex-test is fairly new so i wouldn't be surprised if error messages get mungedFor the t.registerComponent, what is the third parameter ?
t.registerComponent('convex-dev/sharded-counter', schema, ?)
I didn't see anything in the documentation about il
It exepects a glob: Record<string, () => Promise<any>>, I don't understand what it is. Thank you @leethank you @lee it works fine 🙂