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,10 +567,12 @@ defmodule Ash.CodeInterface do
|
||||||
Keyword.split(opts, [:query, :actor, :tenant, :authorize?, :tracer])
|
Keyword.split(opts, [:query, :actor, :tenant, :authorize?, :tracer])
|
||||||
|
|
||||||
{query, query_opts} = Keyword.pop(query_opts, :query)
|
{query, query_opts} = Keyword.pop(query_opts, :query)
|
||||||
|
|
||||||
query_opts = Keyword.put(query_opts, :domain, unquote(domain))
|
query_opts = Keyword.put(query_opts, :domain, unquote(domain))
|
||||||
|
|
||||||
|
query =
|
||||||
case query do
|
case query do
|
||||||
%Ash.Query{resource: unquote(resource)} ->
|
%Ash.Query{resource: unquote(resource)} = query ->
|
||||||
query
|
query
|
||||||
|
|
||||||
%Ash.Query{resource: other_resource} ->
|
%Ash.Query{resource: other_resource} ->
|
||||||
|
@ -578,7 +580,7 @@ defmodule Ash.CodeInterface do
|
||||||
"Query resource #{inspect(other_resource)} does not match expected resource #{inspect(unquote(resource))}."
|
"Query resource #{inspect(other_resource)} does not match expected resource #{inspect(unquote(resource))}."
|
||||||
|
|
||||||
query ->
|
query ->
|
||||||
query
|
Ash.Query.build(unquote(resource), query || [])
|
||||||
end
|
end
|
||||||
|
|
||||||
query =
|
query =
|
||||||
|
@ -586,14 +588,12 @@ defmodule Ash.CodeInterface do
|
||||||
require Ash.Query
|
require Ash.Query
|
||||||
{filters, params} = Map.split(params, unquote(filter_keys))
|
{filters, params} = Map.split(params, unquote(filter_keys))
|
||||||
|
|
||||||
|
|
||||||
query
|
query
|
||||||
|> Kernel.||(unquote(resource))
|
|
||||||
|> Ash.Query.for_read(unquote(action.name), params, query_opts)
|
|> Ash.Query.for_read(unquote(action.name), params, query_opts)
|
||||||
|> Ash.Query.filter(filters)
|
|> Ash.Query.filter(filters)
|
||||||
else
|
else
|
||||||
query
|
Ash.Query.for_read(query, unquote(action.name), params, query_opts)
|
||||||
|> Kernel.||(unquote(resource))
|
|
||||||
|> Ash.Query.for_read(unquote(action.name), params, query_opts)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -641,6 +641,7 @@ defmodule Ash.CodeInterface do
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
quote do
|
quote do
|
||||||
|
|
||||||
if opts[:stream?] do
|
if opts[:stream?] do
|
||||||
Ash.stream!(query, Keyword.drop(opts, [:stream?, :stream_options]))
|
Ash.stream!(query, Keyword.drop(opts, [:stream?, :stream_options]))
|
||||||
else
|
else
|
||||||
|
|
|
@ -75,7 +75,7 @@ defmodule Ash.Resource.Interface do
|
||||||
opts
|
opts
|
||||||
|> Keyword.merge(
|
|> Keyword.merge(
|
||||||
query: [
|
query: [
|
||||||
type: :any,
|
type: {:or, [{:behaviour, Ash.Resource}, {:struct, Ash.Query}, :keyword_list]},
|
||||||
doc: "A query to seed the action with."
|
doc: "A query to seed the action with."
|
||||||
],
|
],
|
||||||
stream?: [
|
stream?: [
|
||||||
|
|
|
@ -38,7 +38,7 @@ defmodule Ash.Test.Actions.GenericActionsTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
action :do_nothing do
|
action :do_nothing do
|
||||||
run fn _ -> :ok end
|
run fn _, _ -> :ok end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue