allenA
Convex Community2y ago
8 replies
allen

Has there been any consideration to

Has there been any consideration to adding v.partial?

The behavior essentially would be v.object but to wrap all children in v.optional.

My typical use case is something like:

//define a table shape:
export const myTableFields = {
  field1: v.number(),
  field2: v.string()
};
//make the table 
export default defineTable(myTableFields);

//expose a partial update mutation
export default internalMutation({
  args: {
    id: v.id('myTable'),
    updates: v.object({
        field1: v.optional(v.number()),
        field2: v.optional(v.string())
    }),
  },
  async handler(ctx, args) {
    await ctx.db.patch(args.id, args.updates);
  },
});


If I was typing args normally, I would use Partial<...> to define this. Likewise, it would helpful to do v.partial(myTableFields) to not have to redefine each field in my mutation args.
Was this page helpful?