Skip to content

Queries

A frontend needs lists, lookups, and live views, and each one normally means a route, argument parsing, paging code, and a response shape to keep in step with the client. In Arc, a query is a static method on a read model. Arc supplies the route, binds the arguments, pages and sorts the result, and, for a live query, streams updates to every subscriber.

GET or QUERY

Client

Arc route

Authentication, authorization, validation

Query method

Renderers, interceptors, paging and sorting

QueryResult

@readModel()
export class TaskItem {
@field(TaskId) id!: TaskId;
@field(TaskTitle) title!: TaskTitle;
@query(service(Tasks))
static allTasks(tasks: Tasks): TaskItem[] { return tasks.all(); }
}

This excerpt is from the Tasks sample read model. GET /api/tasks/listing/all-tasks answers with a query result whose data holds the tasks.

A read model here is a class describing the shape of what you return. Where the data comes from is your choice: an in-memory service, MongoDB, SQL with Drizzle, or a Chronicle projection.

PageUse it when you want to
Model-bound queriesDeclare read models, query methods, and their parameters
Query argumentsBind named, optional, and repeated arguments from the query string
Paging and sortingPage and sort in memory, or return a page your data source cut
Query validationValidate arguments together with QueryValidator
Query pipelineUnderstand the order of checks and result processing
Using the HTTP QUERY methodSend structured arguments in a body
Observable queriesServe a snapshot and live updates from the same route
Subscribe to an observable queryReceive updates over SSE, a WebSocket, or the @cratis/arc client
Multiplexed observable queriesShare one WebSocket or SSE connection across many subscriptions
Observable emission guardsRe-check access for every emission
Query healthInspect the caller’s own hub connections
Using observable queries with curlExplore a live query from a terminal
Query renderersTurn a provider-owned value into data or a page
Read-model interceptionTransform read-model instances before they reach the wire