diff --git a/test/read_test.exs b/test/read_test.exs index 67449c5..13855c7 100644 --- a/test/read_test.exs +++ b/test/read_test.exs @@ -803,6 +803,66 @@ defmodule AshGraphql.ReadTest do }} == Absinthe.run(doc, AshGraphql.Test.Schema, context: %{actor: user}) end + test "a read with a relationship filtered by an actor" do + user = + AshGraphql.Test.User + |> Ash.Changeset.for_create(:create, + name: "My Name" + ) + |> Ash.create!() + + user2 = + AshGraphql.Test.User + |> Ash.Changeset.for_create(:create, + name: "My Name" + ) + |> Ash.create!() + + user_id = user.id + + post = + AshGraphql.Test.Post + |> Ash.Changeset.for_create( + :create, + %{ + author_id: user.id, + text: "a", + published: true + } + ) + |> Ash.create!() + + doc = """ + query { + getPost(id: "#{post.id}") { + authorThatIsActor{ + id + } + } + } + """ + + assert {:ok, + %{ + data: %{ + "getPost" => %{ + "authorThatIsActor" => %{ + "id" => ^user_id + } + } + } + }} = Absinthe.run(doc, AshGraphql.Test.Schema, context: %{actor: user}) + + assert {:ok, + %{ + data: %{ + "getPost" => %{ + "authorThatIsActor" => nil + } + } + }} = Absinthe.run(doc, AshGraphql.Test.Schema, context: %{actor: user2}) + end + test "a multitenant object can be read if tenant is set" do tenant = "Some Tenant" diff --git a/test/support/resources/post.ex b/test/support/resources/post.ex index 2ebc8e2..bbe7cc5 100644 --- a/test/support/resources/post.ex +++ b/test/support/resources/post.ex @@ -604,6 +604,13 @@ defmodule AshGraphql.Test.Post do attribute_writable?(true) end + belongs_to(:author_that_is_actor, AshGraphql.Test.User) do + source_attribute(:author_id) + define_attribute?(false) + public?(true) + filter(expr(id == ^actor(:id))) + end + has_many(:comments, AshGraphql.Test.Comment, public?: true) has_many(:sponsored_comments, AshGraphql.Test.SponsoredComment, public?: true) has_many(:paginated_comments, AshGraphql.Test.Comment, read_action: :paginated, public?: true)