A read model container: the module that declares queries over one model type.
The model is any struct, typically a Chronicle read model. Arc infers the TypeScript shape
from its fields, so the model stays a plain Chronicle read model.
defmodule MyApp.Authors.Listing.Authors do
@moduledoc "Queries over authors."
use Arc.ReadModel, model: MyApp.Authors.Author
@query many: true
def all_authors(_args, _ctx), do: Chronicle.all(MyApp.Authors.Author)
@query params: [id: :uuid], many: false
def by_id(%{id: id}, _ctx), do: Chronicle.read_model(MyApp.Authors.Author, id)
@observe many: true, watch: [MyApp.Authors.Author]
def live_authors(_args, _ctx), do: Chronicle.all(MyApp.Authors.Author)
endEach annotated function takes (args, ctx) where args is a map of the declared, converted
parameters, and returns {:ok, value} or {:error, results}.
Options of use Arc.ReadModel
:model- (required) the struct the queries return:types- overrides for inferred field types in the generated proxy, for exampletypes: [id: :uuid]. Arc infers a type from each struct default; anilor""default is a string.
@query / @observe options
:params- keyword list ofname: type, orname: {type, optional: true}:many- the query returns a list (defaulttrue); Arc appliespage,pageSize,sortByandsortDirectionto lists unless the function returns anArc.Page:authorize/:allow_anonymous- override the module-level declaration:http_method-:getor:queryto prefer one in the generated client
@observe additionally takes:
:watch- Chronicle read model modules; the query re-runs when any of them changes:topics-Arc.Notifiertopics that re-run the query when notified
Summary
Functions
Allows anonymous callers for every query of the module.
Declares who may run every query of the module. See Arc.Authorization.
Functions
Allows anonymous callers for every query of the module.
Declares who may run every query of the module. See Arc.Authorization.