Skip to content

Commit 98ae655

Browse files
authored
fix: add missing description field to fake attrs for generic actions returning union types (#419)
1 parent 374261a commit 98ae655

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

lib/ash_graphql.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ defmodule AshGraphql do
518518
type: action.returns,
519519
constraints: action.constraints,
520520
name: action.name,
521+
description: nil,
521522
from_generic_action?: true
522523
}
523524
end)

test/generic_actions_test.exs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,24 @@ defmodule AshGraphql.GenericActionsTest do
200200
end
201201
end
202202

203+
test "generic action returning an array of union NewType generates valid schema" do
204+
resp =
205+
"""
206+
query {
207+
searchUnions {
208+
... on GenericActionUnionStringResult {
209+
value
210+
}
211+
}
212+
}
213+
"""
214+
|> Absinthe.run(AshGraphql.Test.Schema)
215+
216+
assert {:ok, result} = resp
217+
refute Map.has_key?(result, :errors)
218+
assert %{data: %{"searchUnions" => []}} = result
219+
end
220+
203221
describe "generic action with require_actor? domain" do
204222
test "succeeds when actor is provided via GraphQL context" do
205223
resp =

test/support/resources/resource_with_union.ex

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,30 @@ defmodule AshGraphql.Test.ResourceWithUnion do
5353
def graphql_input_type(_), do: :uniontype_input
5454
end
5555

56+
defmodule GenericActionUnion do
57+
@moduledoc false
58+
59+
use Ash.Type.NewType,
60+
subtype_of: :union,
61+
constraints: [
62+
types: [
63+
string_result: [
64+
type: :string,
65+
tag: :type,
66+
tag_value: "string_result"
67+
],
68+
integer_result: [
69+
type: :integer,
70+
tag: :type,
71+
tag_value: "integer_result"
72+
]
73+
]
74+
]
75+
76+
def graphql_type(_), do: :generic_action_union
77+
def graphql_input_type(_), do: :generic_action_union_input
78+
end
79+
5680
use Ash.Resource,
5781
domain: AshGraphql.Test.Domain,
5882
data_layer: Ash.DataLayer.Ets,
@@ -62,6 +86,7 @@ defmodule AshGraphql.Test.ResourceWithUnion do
6286
type(:resource_with_union)
6387

6488
queries do
89+
action(:search_unions, :search_unions)
6590
end
6691

6792
mutations do
@@ -72,6 +97,12 @@ defmodule AshGraphql.Test.ResourceWithUnion do
7297
actions do
7398
default_accept(:*)
7499

100+
action :search_unions, {:array, GenericActionUnion} do
101+
run(fn _input, _ctx ->
102+
{:ok, []}
103+
end)
104+
end
105+
75106
action :action_with_union_arg, :boolean do
76107
argument(:union_arg, Union, allow_nil?: false)
77108

0 commit comments

Comments
 (0)