MordsithM
Convex Community2y ago
4 replies
Mordsith

Custom query with default argument

I want to write a custom query that adds a default argument.

export const organizationAdminQuery = customQuery(
  query,
  customCtx(async (ctx) => {
    const userId = await getAuthUserIdOrFail(ctx);
    return { ...ctx, userId };
  })
);

// These queries are only available to the organization admin
export const orgAdminQuery = organizationAdminQuery({
  args: { organizationId: v.id("organization") },
  handler: async (ctx, { organizationId }) => {
    return getOrganizationAdmins(organizationId)
  },
});
export const getOrganizationSponsorsQuery = organizationAdminQuery({
  args: { organizationId: v.id("organization") },
  handler: async (ctx, { organizationId }) => {
    return getOrganizationAdmins(organizationId)
  },
});


I would like to add an
organizationId
argument to this custom query so that every consumer of this custom query won't need an
organizationId
in the query args.

I'm trying to achieve this to avoid the repeated
organizationId
in the args param
export const getOrganizationSponsorsQuery = organizationAdminQuery({
  args: {},
  handler: async (ctx, { organizationId }) => {
    return getOrganizationAdmins(organizationId)
  },
});


I got this working using another approach but I'll like to know if this can be done directly with
customQuery
Was this page helpful?