File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff 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
16281658end
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments