mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
improvement: support builder options in read
code interfaces
This commit is contained in:
parent
268b335946
commit
829f6d6e49
3 changed files with 16 additions and 15 deletions
|
@ -567,33 +567,33 @@ defmodule Ash.CodeInterface do
|
|||
Keyword.split(opts, [:query, :actor, :tenant, :authorize?, :tracer])
|
||||
|
||||
{query, query_opts} = Keyword.pop(query_opts, :query)
|
||||
|
||||
query_opts = Keyword.put(query_opts, :domain, unquote(domain))
|
||||
|
||||
case query do
|
||||
%Ash.Query{resource: unquote(resource)} ->
|
||||
query
|
||||
query =
|
||||
case query do
|
||||
%Ash.Query{resource: unquote(resource)} = query ->
|
||||
query
|
||||
|
||||
%Ash.Query{resource: other_resource} ->
|
||||
raise ArgumentError,
|
||||
"Query resource #{inspect(other_resource)} does not match expected resource #{inspect(unquote(resource))}."
|
||||
%Ash.Query{resource: other_resource} ->
|
||||
raise ArgumentError,
|
||||
"Query resource #{inspect(other_resource)} does not match expected resource #{inspect(unquote(resource))}."
|
||||
|
||||
query ->
|
||||
query
|
||||
end
|
||||
query ->
|
||||
Ash.Query.build(unquote(resource), query || [])
|
||||
end
|
||||
|
||||
query =
|
||||
if unquote(filter_keys) && !Enum.empty?(unquote(filter_keys)) do
|
||||
require Ash.Query
|
||||
{filters, params} = Map.split(params, unquote(filter_keys))
|
||||
|
||||
|
||||
query
|
||||
|> Kernel.||(unquote(resource))
|
||||
|> Ash.Query.for_read(unquote(action.name), params, query_opts)
|
||||
|> Ash.Query.filter(filters)
|
||||
else
|
||||
query
|
||||
|> Kernel.||(unquote(resource))
|
||||
|> Ash.Query.for_read(unquote(action.name), params, query_opts)
|
||||
Ash.Query.for_read(query, unquote(action.name), params, query_opts)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -641,6 +641,7 @@ defmodule Ash.CodeInterface do
|
|||
end
|
||||
else
|
||||
quote do
|
||||
|
||||
if opts[:stream?] do
|
||||
Ash.stream!(query, Keyword.drop(opts, [:stream?, :stream_options]))
|
||||
else
|
||||
|
|
|
@ -75,7 +75,7 @@ defmodule Ash.Resource.Interface do
|
|||
opts
|
||||
|> Keyword.merge(
|
||||
query: [
|
||||
type: :any,
|
||||
type: {:or, [{:behaviour, Ash.Resource}, {:struct, Ash.Query}, :keyword_list]},
|
||||
doc: "A query to seed the action with."
|
||||
],
|
||||
stream?: [
|
||||
|
|
|
@ -38,7 +38,7 @@ defmodule Ash.Test.Actions.GenericActionsTest do
|
|||
end
|
||||
|
||||
action :do_nothing do
|
||||
run fn _ -> :ok end
|
||||
run fn _, _ -> :ok end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue