Skuld.Query.Contract (skuld v0.27.3)
View SourceMacro for defining typed batchable fetch contracts with deffetch declarations.
A Query contract defines a set of fetch operations, generating:
- Operation structs — nested struct modules per fetch (e.g.,
MyContract.GetUser) - Caller functions — typed public API returning
computation(return_type), which suspend the current fiber for batched execution - Executor behaviour — typed callbacks for batch execution, one per fetch
- Dispatch function —
__dispatch__/3routes from batch key to executor callback - Introspection —
__query_operations__/0
Summary
Functions
Define a typed fetch operation.
Syntax
deffetch function_name(param :: type(), ...) :: return_type()
deffetch function_name(param :: type(), ...) :: return_type(), cache: bool()Each deffetch declaration generates an operation struct, caller function,
executor callback, and dispatch clause.
@spec with_executors( Skuld.Comp.Types.computation(), [{module(), module()}] | %{required(module()) => module()} ) :: Skuld.Comp.Types.computation()
Install multiple contract/executor pairs in one call.
Accepts either a list of {contract_module, executor_module} tuples or a map.
Examples
comp
|> Skuld.Query.Contract.with_executors([
{MyApp.Queries.Users, MyApp.Queries.Users.EctoExecutor},
{MyApp.Queries.Orders, MyApp.Queries.Orders.EctoExecutor}
])
comp
|> Skuld.Query.Contract.with_executors(%{
MyApp.Queries.Users => MyApp.Queries.Users.EctoExecutor,
MyApp.Queries.Orders => MyApp.Queries.Orders.EctoExecutor
})