From 7f504bbf177f356011cfb3d348861843a3fd062c Mon Sep 17 00:00:00 2001 From: Barnabas Jovanovics Date: Fri, 16 Jun 2023 16:51:50 +0200 Subject: [PATCH] test: add engine deadlock test (#78) --- test/read_test.exs | 27 ++++++++++++++++++++++----- test/support/resources/post.ex | 2 ++ test/support/resources/user.ex | 4 ++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/test/read_test.exs b/test/read_test.exs index a5b8f8f..ceb01ce 100644 --- a/test/read_test.exs +++ b/test/read_test.exs @@ -938,6 +938,7 @@ defmodule AshGraphql.ReadTest do } = result end + @tag :wip test "loading relationships through an unnested union with aliases works" do user = AshGraphql.Test.User @@ -947,16 +948,26 @@ defmodule AshGraphql.ReadTest do post = AshGraphql.Test.Post |> Ash.Changeset.for_create( - :with_comments, + :create, %{ + author_id: user.id, text: "a", - comments: [%{text: "comment", author_id: user.id}], - sponsored_comments: [%{text: "sponsored"}], published: true } ) |> AshGraphql.Test.Api.create!() + post = + post + |> Ash.Changeset.for_update( + :update_with_comments, + %{ + comments: [%{text: "comment", author_id: user.id}], + sponsored_comments: [%{text: "sponsored"}] + } + ) + |> AshGraphql.Test.Api.update!() + resp = """ query postLibrary { @@ -972,8 +983,14 @@ defmodule AshGraphql.ReadTest do ...on SponsoredComment { __typename text - post { + p: post { id + user: author { + name + posts { + id + } + } } } } @@ -1012,7 +1029,7 @@ defmodule AshGraphql.ReadTest do %{ "__typename" => "SponsoredComment", "text" => "sponsored", - "post" => %{"id" => ^post_id} + "p" => %{"id" => ^post_id, "user" => %{"name" => "fred"}} }, %{ "__typename" => "Comment", diff --git a/test/support/resources/post.ex b/test/support/resources/post.ex index de7c5ff..12608a4 100644 --- a/test/support/resources/post.ex +++ b/test/support/resources/post.ex @@ -252,8 +252,10 @@ defmodule AshGraphql.Test.Post do update :update_with_comments do argument(:comments, {:array, :map}) + argument(:sponsored_comments, {:array, :map}) change(manage_relationship(:comments, type: :direct_control)) + change(manage_relationship(:sponsored_comments, type: :direct_control)) end update :update_confirm do diff --git a/test/support/resources/user.ex b/test/support/resources/user.ex index 5b62e04..454c29a 100644 --- a/test/support/resources/user.ex +++ b/test/support/resources/user.ex @@ -53,6 +53,10 @@ defmodule AshGraphql.Test.User do attribute(:name, :string) end + relationships do + has_many(:posts, AshGraphql.Test.Post, destination_attribute: :author_id) + end + calculations do calculate(:name_twice, :string, expr(name <> " " <> name)) end