AshGraphQL embedded resources without attributes

I have a field in a resource that can be an union of two embedded resources. One of these resources have no attributes:

defmodule Core.Marketplace.Payments.Product.Types.Metadata do
  @moduledoc false

  alias Core.Marketplace.Payments.Product.Types

  use AshGraphql.Type

  use Ash.Type.NewType,
    subtype_of: :union,
    constraints: [
      types: [
        credits: [type: Types.Credits, tag: :type, tag_value: :credits],
        one_time_use: [type: Types.OneTimeUse, tag: :type, tag_value: :one_time_use]
      ]
    ]

  def graphql_type(_), do: :payments_product_metadata
end
defmodule Core.Marketplace.Payments.Product.Types.Credits do
  @moduledoc false

  use Ash.Resource,
    data_layer: :embedded,
    extensions: [AshGraphql.Resource]

  attributes do
    attribute :skip_trace, :integer do
      allow_nil? false
      public? true
      default 0

      constraints min: 0
    end

    attribute :export, :integer do
      allow_nil? false
      public? true
      default 0

      constraints min: 0
    end
  end

  graphql do
    type :payments_product_credits
  end
end
defmodule Core.Marketplace.Payments.Product.Types.OneTimeUse do
  @moduledoc false

  use Ash.Resource,
    data_layer: :embedded,
    extensions: [AshGraphql.Resource]

  attributes do
  end

  graphql do
    type :payments_product_one_time_use
  end
end

As you can see, OneTimeUse doesn’t have any fields, without AshGraphQL it works fine, but when I add the AshGraphql.Resource to it, I get this error:

== Compilation error in file lib/core/graphql/schema.ex ==
** (RuntimeError) The resource Core.Marketplace.Payments.Product.Types.OneTimeUse does not have any visible fields in GraphQL.

This typically means that there are no public fields on the resource in question.

    (ash_graphql 1.8.3) lib/resource/resource.ex:4155: AshGraphql.Resource.type_definition/5
    (ash_graphql 1.8.3) lib/ash_graphql.ex:1089: anonymous fn/3 in AshGraphql.get_embedded_types/4
    (elixir 1.18.4) lib/enum.ex:4442: Enum.flat_map_list/2
    (elixir 1.18.4) lib/enum.ex:4446: Enum.flat_map_list/2
    (ash_graphql 1.8.3) lib/ash_graphql.ex:1085: AshGraphql.get_embedded_types/4
    (core 1.230.2) deps/ash_graphql/lib/ash_graphql.ex:285: Core.Marketplace.Dispositions.AshTypes.run/2
    (absinthe 1.7.10) lib/absinthe/pipeline.ex:408: Absinthe.Pipeline.run_phase/3
    (absinthe 1.7.10) lib/absinthe/schema.ex:408: Absinthe.Schema.__after_compile__/2
    (stdlib 6.2.2.2) lists.erl:2146: :lists.foldl/3
    (elixir 1.18.4) lib/kernel/parallel_compiler.ex:423: anonymous fn/5 in Kernel.ParallelCompiler.spawn_workers/8
Compiling 18 files (.ex)
Compiling lib/core/marketplace/ap/appointment.ex (it's taking more than 10s)
Compiling lib/core/marketplace/accounts/user.ex (it's taking more than 10s)

The error is clear, but can’t I workaround it somehow? Adding fields to that resource doesn’t make sense in this context as the struct itself already has enough information for my case.

:thinking: Do you need it to be an embedded resource then? Couldn’t it be a union of an embedded resource and an atom that can only be :one_time_use for example?

I can do that, but I would prefer it to be a struct to make my functions matches more “consise”

Is there any technical reason for AshGraphql not support empty embedded resources? Without AshGraphql it works just fine.

I think its not possible to make that type in GraphQL unfortunately.