Skip to main content

Interface: ValidatedFunction<Ctx, ArgsValidator, Output>

server.ValidatedFunction

The definition of a Convex query, mutation, or action function with argument validation.

Argument validation allows you to assert that the arguments to this function are the expected type.

Example:

import { query } from "./_generated/server";
import { v } from "convex/values";

export const func = query({
args: {
arg: v.string()
},
handler: ({ db }, { arg }) => {...},
});

For security, argument validation should be added to all public functions in production apps.

See UnvalidatedFunction for functions without argument validation.

Type parameters

NameType
CtxCtx
ArgsValidatorextends PropertyValidators
OutputOutput

Properties

args

args: ArgsValidator

A validator for the arguments of this function.

This is an object mapping argument names to validators constructed with v.

import { v } from "convex/values";

const args = {
stringArg: v.string(),
optionalNumberArg: v.optional(v.number()),
}

Defined in

server/registration.ts:426


handler

handler: (ctx: Ctx, args: ObjectType<ArgsValidator>) => Output

Type declaration

▸ (ctx, args): Output

The implementation of this function.

This is a function that takes in the appropriate context and arguments and produces some result.

Parameters
NameTypeDescription
ctxCtxThe context object. This is one of QueryCtx, MutationCtx, or ActionCtx depending on the function type.
argsObjectType<ArgsValidator>The arguments object for this function. This will match the type defined by the argument validator.
Returns

Output

Defined in

server/registration.ts:440