Skip to main content

Interface: ValidatedFunction<Ctx, ArgsValidator, Returns>

For AI agents: see llms.txt for the complete documentation index. Markdown versions are available by adding .md to a page URL or requesting Accept: text/markdown.

server.ValidatedFunction

Deprecated

-- See the type definition for MutationBuilder or similar for the types used for defining Convex functions.

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
ReturnsReturns

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:697


handler​

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

Type declaration​

▸ (ctx, args): Returns

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​

Returns

Defined in​

server/registration.ts:711