Skip to content

Queries

Queries are read-side entry points. A query maps to a return type — a read model, or a collection of read models with [].

query <Name> => <ReturnType>[[]?]
[by <paramName> <Type>]
[filter <paramName> <Type>?]
[authorize <PolicyName> [or <PolicyName>]*]
ClauseMeaning
byThe identifying parameter — the query returns the instance it identifies.
filterAn optional parameter narrowing the result set. Filter types are typically optional (?).
authorizeThe policies that must pass.

A single-instance query identified by a parameter:

query GetInvoice => InvoiceDetailsReadModel
by invoiceId InvoiceId
authorize IsAuthenticated

A collection query with optional filters:

query ListInvoices => InvoiceListReadModel[]
filter status InvoiceStatus?
filter customerId CustomerId?
authorize IsAuthenticated
  • Name queries as descriptive reads: GetInvoice, ListInvoices, GetOverdueInvoices.
  • The return type is a read model built by a projection in the same or another StateView slice.
  • Screens bind to queries with data <ReadModel> via query <QueryName>.