How do correctly compose custom funcitons?

I read https://stack.convex.dev/custom-functions

The problem that i have is that i want to access the context given by a parent custom function. Something like this:

export const authedQuery = customQuery(query, {
    args: {},
    input: async (ctx) => {
        return { ctx: { user }, args: {} };
    },
});

export const insideOrganizationQuery = customQuery(authedQuery, {
    args: { organizationId: v.id("organizations") },
    input: async (ctx, { organizationId }) => {
        ctx.user; // TS Error: Property 'user' does not exist
        return { ctx: { }, args: {} };
    },
});

export const get = insideOrganizationQuery({
    handler(ctx) {
        ctx.organization; // Works
        ctx.user; // // TS Error: Property 'user' does not exist
    },
})

My use case would benefit of 3 nested custom queries, where the last 2 have args.

Is there a pattern to allow composing them correctly, allowing the use of the additional ctx/args?
Was this page helpful?