cql

Evaluate a CQL query in real-time using a tag function.

This tag function  evaluates a  CQL query on the server side.

Croct's mascot winking
Router compatibility

This function is only compatible with the App Router , but you can alternatively use the evaluate function.

Both the cql tag and the evaluate function are similar in functionality. The main difference between them is that the cql tag automatically handles query interpolation for you, but it does not support specifying options. So if you do not need to specify options or interpolation, you can use them interchangeably.

Signature

This function has the following signature:

function cql<T extends JsonValue>(query: string): Promise<T>;

The result is a Promise that resolves to the result of the evaluation.

Example

Here is a minimal example of how to use this function:

components/DocsLink.jsx
1234567891011
import {cql} from '@croct/plug-next/server';
export function DocsLink() {
const isDeveloper = cql`user's persona is 'developer'`;
return (
isDeveloper
? <a href="/docs">View docs</a>
: <a href="/share">Share with your developer</a>
);
}

Parameters

The following list describes the supported parameters:

query
string

The  CQL query to evaluate, with a maximum length of 500 characters.