fix: drop proper opts keys when calling api in code interface (#608)

This commit is contained in:
Dmitry Maganov 2023-06-09 17:16:15 +03:00 committed by GitHub
parent 5e93ebe9bd
commit f5238674a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -449,7 +449,7 @@ defmodule Ash.CodeInterface do
unquote(api).run_action( unquote(api).run_action(
action_input, action_input,
Keyword.drop(opts, [:actor, :changeset, :tenant, :authorize?, :tracer]) Keyword.drop(opts, [:input, :actor, :tenant, :authorize?, :tracer])
) )
end end
end end
@ -477,7 +477,8 @@ defmodule Ash.CodeInterface do
end) end)
action_input = action_input =
(opts[:input] || unquote(resource)) opts[:input]
|> Kernel.||(unquote(resource))
|> Ash.ActionInput.for_action( |> Ash.ActionInput.for_action(
unquote(action.name), unquote(action.name),
input, input,
@ -486,7 +487,7 @@ defmodule Ash.CodeInterface do
unquote(api).run_action!( unquote(api).run_action!(
action_input, action_input,
Keyword.drop(opts, [:actor, :changeset, :authorize?, :tracer]) Keyword.drop(opts, [:input, :actor, :tenant, :authorize?, :tracer])
) )
end end
end end
@ -543,7 +544,14 @@ defmodule Ash.CodeInterface do
if unquote(interface.get? || action.get?) do if unquote(interface.get? || action.get?) do
query query
|> unquote(api).read_one( |> unquote(api).read_one(
Keyword.drop(opts, [:query, :tenant, :authorize?, :actor, :not_found_error?]) Keyword.drop(opts, [
:query,
:not_found_error?,
:actor,
:tenant,
:authorize?,
:tracer
])
) )
|> case do |> case do
{:ok, nil} -> {:ok, nil} ->
@ -563,7 +571,7 @@ defmodule Ash.CodeInterface do
else else
unquote(api).read( unquote(api).read(
query, query,
Keyword.drop(opts, [:query, :tenant, :actor, :authorize?]) Keyword.drop(opts, [:query, :actor, :tenant, :authorize?, :tracer])
) )
end end
end end
@ -621,7 +629,14 @@ defmodule Ash.CodeInterface do
if unquote(interface.get? || action.get?) do if unquote(interface.get? || action.get?) do
query query
|> unquote(api).read_one!( |> unquote(api).read_one!(
Keyword.drop(opts, [:query, :tenant, :authorize?, :actor, :not_found_error?]) Keyword.drop(opts, [
:query,
:not_found_error?,
:actor,
:tenant,
:authorize?,
:tracer
])
) )
|> case do |> case do
nil -> nil ->
@ -638,7 +653,7 @@ defmodule Ash.CodeInterface do
else else
unquote(api).read!( unquote(api).read!(
query, query,
Keyword.drop(opts, [:query, :tenant, :actor, :authorize?]) Keyword.drop(opts, [:query, :actor, :tenant, :authorize?, :tracer])
) )
end end
end end
@ -677,7 +692,7 @@ defmodule Ash.CodeInterface do
unquote(api).create( unquote(api).create(
changeset, changeset,
Keyword.drop(opts, [:actor, :changeset, :tenant, :authorize?, :tracer]) Keyword.drop(opts, [:changeset, :actor, :tenant, :authorize?, :tracer])
) )
end end
end end
@ -705,7 +720,8 @@ defmodule Ash.CodeInterface do
end) end)
changeset = changeset =
(opts[:changeset] || unquote(resource)) opts[:changeset]
|> Kernel.||(unquote(resource))
|> Ash.Changeset.for_create( |> Ash.Changeset.for_create(
unquote(action.name), unquote(action.name),
input, input,
@ -714,7 +730,7 @@ defmodule Ash.CodeInterface do
unquote(api).create!( unquote(api).create!(
changeset, changeset,
Keyword.drop(opts, [:actor, :changeset, :authorize?, :tracer]) Keyword.drop(opts, [:changeset, :actor, :tenant, :authorize?, :tracer])
) )
end end
end end