thawke
Empty Result on Generic Action with graphql_unnested_unions
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?
First Post!
zachdaniel
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









