evaluate
Learn how to evaluate a CQL query on the server.
This function evaluates a CQL query against the current visitor’s context on the server.
Call it from a loader, passing the loader’s context as the scope option, to personalize or segment the response before it renders.
Signature
This function has the following signature:
function evaluate<T extends JsonValue>(query: string, options: EvaluationOptions<T>): Promise<T>;Example
Evaluate a query in a loader:
import {evaluate} from '@croct/plug-hydrogen/server';
const country = await evaluate<string | null>("location's country", { scope: context,});Parameters
The following list describes the supported parameters:
- querystring
The CQL query to evaluate.
- optionsobject
The evaluation options.
- scopeCroctContext
The Hydrogen load context for the current request.
- context(optional)EvaluationContext
The evaluation context to attach to the query. Use it to pass custom attributes that personalize or segment the result. These values are accessible in the context variable.
- fallback(optional)T
The value to return when the evaluation fails, such as on a network error or timeout.
- scope