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

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New

Other popular topics Top

grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52774 488
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
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
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement