igor9silvaI
Convex Communityβ€’15mo agoβ€’
21 replies
igor9silva

Shared functionality patterns and authz

being honest, it feels very not ideal,
as i'll need to be constantly thinking about it

e.g
I have a setStatus function to patch 1 field.
I need it to be it's own mutation so I can call it from an action (LLM calling) with runMutation(), but I also want it to be a pure function so I can call it efficiently from another mutation.
export const setStatus = internalMutation({
    args: {
        actionId: v.id('taskActions'),
        status: taskActionStatuses,
    },
    handler: async (ctx, { actionId, status }) => {
        await ctx.db.patch(actionId, {
            status,
            isDone: status === 'succeeded' || status === 'failed' || status === 'cancelled',
        });
    },
});


If I were able to use runQuery() efficiently (read as equal to calling the function directly) from other queries, or just calling it straight as I did with currentUser above (even better!), I would not have to worry about splitting it into two functions ever. It would just work and actually force me to abstract properly (it happened a few times before I found out I should not be doing it πŸ˜…).

it's at least a missed opportunity
------------------------------------
BTW thank you guys for being so open and attentive here, I hope I'm not being too much of a bother
Was this page helpful?