I have a generic action on a resource that returns a union type. If I mark types with graphql_unnested_unions then the type’s fields disappear in the response. This happens for both embedded resources and typed structs. Removing or untagging the type in graphql_unnested_unions wraps the type in a value and the fields appear fine under that.
Example Union definition:
defmodule Api.Example.UnnestedUnion do
use Ash.Type.NewType,
subtype_of: :union,
constraints: [
types: [
embedded: [
type: Api.Example.Embedded
],
typed_struct: [
type: Api.Example.TypedStruct
]
]
]
use AshGraphql.Type
@impl true
def graphql_type(_), do: :unnested_union
@impl true
def graphql_unnested_unions(_constraints), do: [:embedded, :typed_struct]
end
My generic action:
action :array_unnested_embedded_union, {:array, Api.Example.UnnestedUnion} do
run fn _, _ ->
{:ok,
[
%Ash.Union{
type: :embedded,
value: %Api.Example.Embedded{title: "Hello World"}
}
]}
end
end
Running a graphql query against a generic action that returns an array of a union like above seems to return:
{
"data": {
// Without graphql_unnested_unions
"nestedEmbeddedUnion": [
{
"value": {
"title": "Hello World"
}
}
],
"nestedTypedStructUnion": [
{
"value": {
"title": "Hello World"
}
}
],
// With graphql_unnested_unions
"unnestedEmbeddedUnion": [
{}
],
"unnestedTypedStructUnion": [
{}
]
}
}
The typing in the graphql schema appears correct and all the fields show up correctly, they just don’t seem to come back properly when queried if they are unnested. I created a small repo with a reproduction. Is this a bug or am I doing something wrong in my code?






















