thawke

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

zachdaniel

Creator of Ash

Definitely seems like a bug. Please open an issue and I will look into it :person_bowing:

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39467 209
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement