David Alonso
David Alonso8mo ago

Can internal query be recursive?

It doesn't seem like it but just double checking
2 Replies
lee
lee8mo ago
The handler can be recursive.
function qHandler(ctx, args) {
// do some stuff
qHandler(ctx, args);
// more stuff
}

export const foo = internalQuery({args: {...}, handler: qHandler });
function qHandler(ctx, args) {
// do some stuff
qHandler(ctx, args);
// more stuff
}

export const foo = internalQuery({args: {...}, handler: qHandler });
calling the query itself recursively involves overhead for argument validation and making it into a transaction, so I wouldn't recommend it even if it were possible. Making the handler recursive or calling a recursive function from the query is usually better
David Alonso
David AlonsoOP8mo ago
thanks!

Did you find this page helpful?