Queries
Queries are read-side entry points. A query maps to a return type — a read model, or a collection of read models with [].
Syntax
Section titled “Syntax”query <Name> => <ReturnType>[[]?] [by <paramName> <Type>] [filter <paramName> <Type>?] [authorize <PolicyName> [or <PolicyName>]*]| Clause | Meaning |
|---|---|
by | The identifying parameter — the query returns the instance it identifies. |
filter | An optional parameter narrowing the result set. Filter types are typically optional (?). |
authorize | The policies that must pass. |
Examples
Section titled “Examples”A single-instance query identified by a parameter:
query GetInvoice => InvoiceDetailsReadModel by invoiceId InvoiceId authorize IsAuthenticatedA collection query with optional filters:
query ListInvoices => InvoiceListReadModel[] filter status InvoiceStatus? filter customerId CustomerId? authorize IsAuthenticatedGuidance
Section titled “Guidance”- Name queries as descriptive reads:
GetInvoice,ListInvoices,GetOverdueInvoices. - The return type is a read model built by a projection in the same or another
StateViewslice. - Screens bind to queries with
data <ReadModel> via query <QueryName>.