djbalinD
Convex Communityβ€’13mo agoβ€’
3 replies
djbalin

Calling `ctx.runQuery` from `query`

I seem to have my world shaken by Convex almost every day (in a good way)! I always thought ctx.runQuery/runMutation was only possible from actions, and that calling a query from within a query was not possible, but that regular TS helper functions should be employed (e.g. as @erquhart mentions here How to call a function within another function?).

I just found out that it is indeed possible by just using ctx.runQuery. That comes with this warning/info: often you can call the query's function directly? Is this what you mean/propose?:


export const getAllCategories = authQuery({
  handler: async (ctx) => {
    return ...
  },
})

export const testQuery = authQuery({
  handler: async (ctx) => {
    const categories = await getAllCategories(ctx, {})
  },
})
Was this page helpful?