diff --git a/test/read_test.exs b/test/read_test.exs index b9254083..fa13ddb5 100644 --- a/test/read_test.exs +++ b/test/read_test.exs @@ -594,6 +594,44 @@ defmodule AshGraphql.ReadTest do assert %{data: %{"getCompositePrimaryKey" => %{"id" => ^id}}} = result 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!() + + post = + AshGraphql.Test.Post + |> Ash.Changeset.for_create(:create, text: "foo", published: true) + |> AshGraphql.Test.Api.create!() + + AshGraphql.Test.Comment + |> Ash.Changeset.for_create(:create, %{text: "stuff"}) + |> Ash.Changeset.force_change_attribute(:post_id, post.id) + |> AshGraphql.Test.Api.create!() + + resp = + """ + query Post($id: ID!) { + getPost(id: $id) { + latestCommentAt + } + } + """ + |> Absinthe.run(AshGraphql.Test.Schema, + variables: %{ + "id" => post.id + } + ) + + assert {:ok, result} = resp + assert result[:data]["getPost"]["latestCommentAt"] + end + test "a read with custom types works" do AshGraphql.Test.Post |> Ash.Changeset.for_create(:create, diff --git a/test/support/resources/comment.ex b/test/support/resources/comment.ex index f3352cd1..dc92870c 100644 --- a/test/support/resources/comment.ex +++ b/test/support/resources/comment.ex @@ -38,6 +38,16 @@ defmodule AshGraphql.Test.Comment do writable?(false) default(:comment) end + + create_timestamp(:created_at) + end + + calculations do + calculate( + :timestamp, + :utc_datetime_usec, + expr(created_at) + ) end relationships do diff --git a/test/support/resources/post.ex b/test/support/resources/post.ex index fabcc340..6a9632b0 100644 --- a/test/support/resources/post.ex +++ b/test/support/resources/post.ex @@ -365,6 +365,7 @@ defmodule AshGraphql.Test.Post do aggregates do count(:comment_count, :comments) + max(:latest_comment_at, [:comments], :timestamp) end relationships do