fix: properly fetch aliased all attributes

This commit is contained in:
Zach Daniel 2023-06-12 13:19:07 -04:00
parent dcc7e045b9
commit 74211ef3f4
6 changed files with 10 additions and 10 deletions

View file

@ -2183,9 +2183,9 @@ defmodule AshGraphql.Graphql.Resolver do
Absinthe.Resolution.put_result(resolution, {:ok, result})
end
def resolve_attribute(%{source: parent} = resolution, name) do
def resolve_attribute(%{source: parent} = resolution, {name, type, _constraints}) do
value =
if resolution.definition.alias do
if resolution.definition.alias && Ash.Type.can_load?(type) do
Map.get(parent.calculations, {:__ash_graphql_attribute__, resolution.definition.alias})
else
Map.get(parent, name)

View file

@ -3485,7 +3485,7 @@ defmodule AshGraphql.Resource do
]
else
[
{{AshGraphql.Graphql.Resolver, :resolve_attribute}, name}
{{AshGraphql.Graphql.Resolver, :resolve_attribute}, {name, type, constraints}}
]
end
end

View file

@ -140,7 +140,7 @@ defmodule AshGraphql.MixProject do
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:ash, ash_version("~> 2.9 and >= 2.9.24")},
{:ash, ash_version("~> 2.9 and >= 2.9.28")},
{:dataloader, "~> 1.0"},
{:absinthe_plug, "~> 1.4"},
{:absinthe, "~> 1.7"},

View file

@ -1,7 +1,7 @@
%{
"absinthe": {:hex, :absinthe, "1.7.1", "aca6f64994f0914628429ddbdfbf24212747b51780dae189dd98909da911757b", [:mix], [{:dataloader, "~> 1.0.0", [hex: :dataloader, repo: "hexpm", optional: true]}, {:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 1.2.2 or ~> 1.3.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c0c4dbd93881fa3bfbad255608234b104b877c2a901850c1fe8c53b408a72a57"},
"absinthe_plug": {:hex, :absinthe_plug, "1.5.8", "38d230641ba9dca8f72f1fed2dfc8abd53b3907d1996363da32434ab6ee5d6ab", [:mix], [{:absinthe, "~> 1.5", [hex: :absinthe, repo: "hexpm", optional: false]}, {:plug, "~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "bbb04176647b735828861e7b2705465e53e2cf54ccf5a73ddd1ebd855f996e5a"},
"ash": {:hex, :ash, "2.9.26", "5281c526d0b416d7f6fd6455326cdb1aee0239089916b8be1f6460b02cf3d3ed", [:mix], [{:comparable, "~> 1.0", [hex: :comparable, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:earmark, "~> 1.4", [hex: :earmark, repo: "hexpm", optional: true]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8.0", [hex: :ets, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: false]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:spark, "~> 1.0", [hex: :spark, repo: "hexpm", optional: false]}, {:stream_data, "~> 0.5.0", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b0148214a27ecefc99d77d55c739485625de0f8aa4d8b4b1b3d8cd7f2d97045b"},
"ash": {:hex, :ash, "2.9.28", "02941c002eeb494aa8b4fcbd6f5de92590f24ea75114e279e51c815f758abf21", [:mix], [{:comparable, "~> 1.0", [hex: :comparable, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:earmark, "~> 1.4", [hex: :earmark, repo: "hexpm", optional: true]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8.0", [hex: :ets, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: false]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:spark, "~> 1.0", [hex: :spark, repo: "hexpm", optional: false]}, {:stream_data, "~> 0.5.0", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "6189c825a85957bc180ef6150bc7f721a015bf62ef7f0494e824b4387207d914"},
"bunt": {:hex, :bunt, "0.2.1", "e2d4792f7bc0ced7583ab54922808919518d0e57ee162901a16a1b6664ef3b14", [:mix], [], "hexpm", "a330bfb4245239787b15005e66ae6845c9cd524a288f0d141c148b02603777a5"},
"certifi": {:hex, :certifi, "2.9.0", "6f2a475689dd47f19fb74334859d460a2dc4e3252a3324bd2111b8f0429e7e21", [:rebar3], [], "hexpm", "266da46bdb06d6c6d35fde799bcb28d36d985d424ad7c08b5bb48f5b5cdd4641"},
"comparable": {:hex, :comparable, "1.0.0", "bb669e91cedd14ae9937053e5bcbc3c52bb2f22422611f43b6e38367d94a495f", [:mix], [{:typable, "~> 0.1", [hex: :typable, repo: "hexpm", optional: false]}], "hexpm", "277c11eeb1cd726e7cd41c6c199e7e52fa16ee6830b45ad4cdc62e51f62eb60c"},

View file

@ -211,7 +211,6 @@ defmodule AliasTest do
AshGraphql.Test.User
|> Ash.Changeset.for_create(:create, name: "test")
|> AshGraphql.Test.Api.create!()
|> IO.inspect()
post =
AshGraphql.Test.Post
@ -219,7 +218,7 @@ defmodule AliasTest do
text: "foo",
published: true,
score: 9.8,
auhtor_id: author.id
author_id: author.id
)
|> AshGraphql.Test.Api.create!()
@ -247,7 +246,7 @@ defmodule AliasTest do
assert %{
data: %{
"getPost" => %{"author" => %{"name" => ^name}}
"getPost" => %{"writer" => %{"name" => ^name}}
}
} = result
end

View file

@ -321,9 +321,10 @@ defmodule AshGraphql.Test.Post do
attribute(:embed_union_unnested, AshGraphql.Types.EmbedUnionNewTypeUnnested)
attribute(:enum_new_type, AshGraphql.Types.EnumNewType)
attribute(:string_new_type, AshGraphql.Types.StringNewType)
attribute :required_string, :string do
allow_nil? false
default "test"
default("test")
end
create_timestamp(:created_at, private?: false)
@ -342,7 +343,7 @@ defmodule AshGraphql.Test.Post do
end
aggregates do
count :comment_count, :comments
count(:comment_count, :comments)
end
relationships do