Skip to content

Query Configuration

Queries can be configured for service routing and endpoint behavior in both React and non-React environments.

Per query:

query.setMicroservice('inventory-service');

In React applications, configure this globally with <Arc microservice="..." />.

Per query:

query.setApiBasePath('/api/v1');

In React applications, set this globally with <Arc apiBasePath="..." />.

Observable Query Transport (queryDirectMode)

Section titled “Observable Query Transport (queryDirectMode)”

By default, observable queries use centralized hub endpoints. Set Globals.queryDirectMode = true to bypass the hub and connect directly per query.

import { Globals } from '@cratis/arc';
Globals.queryDirectMode = true;
ValueDescription
false (default)Route through /.cratis/queries/sse or /.cratis/queries/ws.
trueConnect directly to each query URL using the separately selected SSE or WebSocket transport.

In React, this is usually configured through <Arc queryDirectMode={...} />. See React query integration.

Query Cache Retention (queryCacheRetentionMs)

Section titled “Query Cache Retention (queryCacheRetentionMs)”

Controls how long (in milliseconds) the query cache keeps an entry alive after the last subscriber releases it. The default is 30 000 ms (30 seconds).

import { Globals } from '@cratis/arc';
// Keep cached data for 60 seconds after the last subscriber unmounts.
Globals.queryCacheRetentionMs = 60_000;
// Schedule zero-delay cleanup after the last subscriber releases the entry.
Globals.queryCacheRetentionMs = 0;

In React applications, set this through <Arc queryCacheRetentionMs={...} /> instead of modifying Globals directly. See React query configuration.

Ordinary query method selection (Get, Query, Auto) is separate from observable transport selection. See using the HTTP QUERY method for global, per-query, and resolver configuration.

Native streaming handshakes cannot attach arbitrary callback headers; see transport credentials. React bindings also mutate global settings, so nested providers are not independent authenticated hubs.