Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add opts to all Ash.load calls #260

Merged
merged 1 commit into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 33 additions & 11 deletions lib/ash_json_api/controllers/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,13 @@ defmodule AshJsonApi.Controllers.Helpers do

with {:ok, result} <- Ash.run_action(action_input),
{:ok, result} <-
Ash.load(result, fields(request, request.resource), reuse_values?: true),
{:ok, result} <- Ash.load(result, request.includes_keyword) do
Ash.load(
result,
fields(request, request.resource),
Request.load_opts(request, reuse_values?: true)
),
{:ok, result} <-
Ash.load(result, request.includes_keyword, Request.load_opts(request)) do
Request.assign(request, :result, result)
else
{:error, error} ->
Expand Down Expand Up @@ -222,11 +227,16 @@ defmodule AshJsonApi.Controllers.Helpers do

with {:ok, result} <- Ash.run_action(action_input),
{:ok, result} <-
Ash.load(result, fields(request, request.resource), reuse_values?: true),
Ash.load(
result,
fields(request, request.resource),
Request.load_opts(request, reuse_values?: true)
),
{:ok, result} <-
Ash.load(
result,
request.includes_keyword || []
request.includes_keyword || [],
Request.load_opts(request)
) do
Request.assign(request, :result, result)
else
Expand Down Expand Up @@ -302,11 +312,16 @@ defmodule AshJsonApi.Controllers.Helpers do

with {:ok, result} <- Ash.run_action(action_input),
{:ok, result} <-
Ash.load(result, fields(request, request.resource), reuse_values?: true),
Ash.load(
result,
fields(request, request.resource),
Request.load_opts(request, reuse_values?: true)
),
{:ok, result} <-
Ash.load(
result,
request.includes_keyword || []
request.includes_keyword || [],
Request.load_opts(request)
) do
Request.assign(request, :result, result)
else
Expand Down Expand Up @@ -418,7 +433,7 @@ defmodule AshJsonApi.Controllers.Helpers do
|> case do
{:ok, record} ->
record
|> Ash.load(fields(request, request.resource), Request.opts(request))
|> Ash.load(fields(request, request.resource), Request.load_opts(request))
|> case do
{:ok, updated} ->
request
Expand Down Expand Up @@ -454,11 +469,16 @@ defmodule AshJsonApi.Controllers.Helpers do

with {:ok, result} <- Ash.run_action(action_input),
{:ok, result} <-
Ash.load(result, fields(request, request.resource), reuse_values?: true),
Ash.load(
result,
fields(request, request.resource),
Request.load_opts(request, reuse_values?: true)
),
{:ok, result} <-
Ash.load(
result,
request.includes_keyword || []
request.includes_keyword || [],
Request.load_opts(request)
) do
Request.assign(request, :result, result)
else
Expand Down Expand Up @@ -624,8 +644,10 @@ defmodule AshJsonApi.Controllers.Helpers do
end

with {:ok, result} <- Ash.run_action(action_input),
{:ok, result} <- Ash.load(result, load_lazy, reuse_values?: true),
{:ok, result} <- Ash.load(result, load) do
{:ok, result} <-
Ash.load(result, load_lazy, Request.load_opts(request, reuse_values?: true)),
{:ok, result} <-
Ash.load(result, load, Request.load_opts(request)) do
request
|> Request.assign(:result, result)
|> Request.assign(:record_from_path, result)
Expand Down
7 changes: 7 additions & 0 deletions lib/ash_json_api/request.ex
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ defmodule AshJsonApi.Request do
]
end

def load_opts(request, merge) do
Keyword.merge(
load_opts(request),
merge
)
end

def opts(request, merge \\ []) do
page_params = Map.get(request.assigns, :page)

Expand Down
Loading