How to pass args to Api.read

I'm trying to accomplish something like this
Spendable.Api.read!(BudgetAllocationTemplate, action: :list, search: socket.assigns[:search])
Spendable.Api.read!(BudgetAllocationTemplate, action: :list, search: socket.assigns[:search])
for an action that looks like this
read :list do
argument :search, :string

prepare before_action(fn query ->
IO.inspect {query, arg(:search)}
end)

prepare build(sort: [:name])
end
read :list do
argument :search, :string

prepare before_action(fn query ->
IO.inspect {query, arg(:search)}
end)

prepare build(sort: [:name])
end
4 Replies
ZachDaniel
ZachDaniel•2y ago
BudgetAllocationTemplate |> Ash.Query.for_read(args) |> Api.read!() is the way currently I don't think there is a way to do it as an option to Api.read right now, but we could potentially add one
michaelst
michaelstOP•2y ago
Thanks! needed a slight tweak on that, but got it working
BudgetAllocationTemplate
|> Ash.Query.for_read(:list, search: socket.assigns[:search])
|> Spendable.Api.read!()
BudgetAllocationTemplate
|> Ash.Query.for_read(:list, search: socket.assigns[:search])
|> Spendable.Api.read!()
ZachDaniel
ZachDaniel•2y ago
oh, yeah sorry forgot about the action 🙂
michaelst
michaelstOP•2y ago
No worries, appreciate you pointing me in the right direction loving this new support/question model, search just answered a different question for me

Did you find this page helpful?