Skip to content

Commit 370109b

Browse files
committed
Add failing test for a calculation that uses a :struct return type and a constraint with an otherwise unreferenced NewType
1 parent ac4d863 commit 370109b

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

test/read_test.exs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,4 +1625,34 @@ defmodule AshGraphql.ReadTest do
16251625
} = result
16261626
end
16271627
end
1628+
1629+
describe "calculations" do
1630+
test "loads calculated struct type that uses constraint" do
1631+
post =
1632+
AshGraphql.Test.Post
1633+
|> Ash.Changeset.for_create(:create,
1634+
text: "a",
1635+
published: true
1636+
)
1637+
|> Ash.create!()
1638+
1639+
resp =
1640+
"""
1641+
query postLibrary {
1642+
postLibrary(sort: {field: TEXT}) {
1643+
structCalc {
1644+
some
1645+
}
1646+
}
1647+
}
1648+
"""
1649+
|> Absinthe.run(AshGraphql.Test.Schema)
1650+
1651+
assert {:ok, result} = resp
1652+
1653+
refute Map.has_key?(result, :errors)
1654+
1655+
assert %{data: %{"postLibrary" => [%{"structCalc" => %{"some" => "string"}}]}} = result
1656+
end
1657+
end
16281658
end

test/support/resources/post.ex

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,16 @@ defmodule AshGraphql.Test.Post do
625625
end,
626626
public?: true
627627
)
628+
629+
calculate(
630+
:struct_calc,
631+
:struct,
632+
fn records, _ ->
633+
Enum.map(records, fn _ -> %{some: "string"} end)
634+
end,
635+
public?: true,
636+
constraints: [instance_of: AshGraphql.Test.UnreferencedStructType]
637+
)
628638
end
629639

630640
aggregates do
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
defmodule AshGraphql.Test.UnreferencedType do
2+
@moduledoc false
3+
use Ash.Type.NewType,
4+
subtype_of: :map,
5+
constraints: [
6+
fields: [
7+
some: [
8+
type: :string,
9+
allow_nil?: false
10+
]
11+
]
12+
]
13+
end

0 commit comments

Comments
 (0)