Skip to content

Commit

Permalink
fix: support aggregates over calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Aug 30, 2023
1 parent 0c869aa commit 1d69d8e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
6 changes: 3 additions & 3 deletions lib/resource/resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1854,7 +1854,7 @@ defmodule AshGraphql.Resource do
with field when not is_nil(field) <- field,
related when not is_nil(related) <-
Ash.Resource.Info.related(resource, relationship_path),
attr when not is_nil(attr) <- Ash.Resource.Info.attribute(related, field) do
attr when not is_nil(attr) <- Ash.Resource.Info.field(related, field) do
attr.type
end

Expand Down Expand Up @@ -2271,7 +2271,7 @@ defmodule AshGraphql.Resource do
with field when not is_nil(field) <- aggregate.field,
related when not is_nil(related) <-
Ash.Resource.Info.related(resource, aggregate.relationship_path),
attr when not is_nil(attr) <- Ash.Resource.Info.attribute(related, aggregate.field) do
attr when not is_nil(attr) <- Ash.Resource.Info.field(related, aggregate.field) do
attr.type
end

Expand Down Expand Up @@ -3480,7 +3480,7 @@ defmodule AshGraphql.Resource do
with field when not is_nil(field) <- aggregate.field,
related when not is_nil(related) <-
Ash.Resource.Info.related(resource, aggregate.relationship_path),
attr when not is_nil(attr) <- Ash.Resource.Info.attribute(related, aggregate.field) do
attr when not is_nil(attr) <- Ash.Resource.Info.field(related, aggregate.field) do
{attr.type, attr.constraints}
else
_ ->
Expand Down
15 changes: 7 additions & 8 deletions test/read_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -595,14 +595,13 @@ defmodule AshGraphql.ReadTest do
end

test "aggregate of a calculation" do
post =
AshGraphql.Test.Post
|> Ash.Changeset.for_create(:create,
text: "foo",
published: true,
score: 9.8
)
|> AshGraphql.Test.Api.create!()
AshGraphql.Test.Post
|> Ash.Changeset.for_create(:create,
text: "foo",
published: true,
score: 9.8
)
|> AshGraphql.Test.Api.create!()

post =
AshGraphql.Test.Post
Expand Down
2 changes: 1 addition & 1 deletion test/support/types/status.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule AshGraphql.Test.Status do
end

@impl true
def cast_stored(value, nil), do: {:ok, nil}
def cast_stored(nil, _), do: {:ok, nil}

def cast_stored(value, _) when value in @values do
{:ok, value}
Expand Down

0 comments on commit 1d69d8e

Please sign in to comment.