Skip to content

Commit

Permalink
fix: load fields after building query for action
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Nov 5, 2024
1 parent aaf0813 commit 61a8b23
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions lib/graphql/resolver.ex
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ defmodule AshGraphql.Graphql.Resolver do
|> Ash.Query.set_context(get_context(context))
|> set_query_arguments(action, args)
|> select_fields(resource, resolution, type_name)
|> Ash.Query.for_read(action, %{},
actor: opts[:actor],
domain: domain,
authorize?: AshGraphql.Domain.Info.authorize?(domain)
)
|> load_fields(
[
domain: domain,
Expand All @@ -343,13 +348,7 @@ defmodule AshGraphql.Graphql.Resolver do
)

result =
query
|> Ash.Query.for_read(action, %{},
actor: opts[:actor],
domain: domain,
authorize?: AshGraphql.Domain.Info.authorize?(domain)
)
|> Ash.read_one(opts)
Ash.read_one(query, opts)

result =
add_read_metadata(
Expand Down Expand Up @@ -443,15 +442,22 @@ defmodule AshGraphql.Graphql.Resolver do
),
relay?
),
initial_query <-
query <-
query
|> Ash.Query.set_tenant(Map.get(context, :tenant))
|> Ash.Query.set_context(get_context(context))
|> set_query_arguments(action, args)
|> select_fields(resource, resolution, type_name, result_fields),
query <-
query
|> Ash.Query.for_read(action, %{},
actor: Map.get(context, :actor),
domain: domain,
authorize?: AshGraphql.Domain.Info.authorize?(domain)
),
query <-
load_fields(
initial_query,
query,
[
domain: domain,
tenant: Map.get(context, :tenant),
Expand All @@ -465,14 +471,7 @@ defmodule AshGraphql.Graphql.Resolver do
context,
result_fields
),
{:ok, page} <-
query
|> Ash.Query.for_read(action, %{},
actor: Map.get(context, :actor),
domain: domain,
authorize?: AshGraphql.Domain.Info.authorize?(domain)
)
|> Ash.read(opts) do
{:ok, page} <- Ash.read(query, opts) do
result = paginate(resource, gql_query, action, page, relay?)
{result, [query, result]}
else
Expand Down

0 comments on commit 61a8b23

Please sign in to comment.