Skip to main content

createExpressionValidator()

createExpressionValidator(functionMeta?: ExpressionFunctionMetaRegistry): QueryValidator

Defined in: expr/src/utils/createExpressionValidator.ts:29

Configure-once factory returning a QueryValidator that flags rules whose lhs/rhs expressions are invalid — unknown function, arity mismatch, or empty field reference — checked against functionMeta merged over the built-in defaultFunctionMeta (the same merge QueryBuilderExpressions applies, so one metadata registry drives the UI and validation alike).

The returned validator produces a sparse ValidationMap: only invalid, expression-bearing rules get an entry ({ valid: false, reasons }), keyed by rule.id. Rules without expressions, valid rules, and rules lacking an id are omitted and thus treated as valid. Validation is format-agnostic — it does not check per-format serializers; the rule processors handle serializer presence per export format.

Pass the result as formatQuery's validator option to annotate format: 'diagnostics' output and to skip invalid rules from standard exports, or to a <QueryBuilder>'s validator prop for live in-UI feedback.

Parameters

ParameterType
functionMeta?ExpressionFunctionMetaRegistry

Returns

QueryValidator


caution

API documentation is generated from the latest commit on the main branch. It may be somewhat inconsistent with official releases of React Query Builder.