sezaru

sezaru

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.

Showing Posts 1 to 3

zachdaniel

zachdaniel

Creator of Ash

: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?

sezaru

sezaru OP

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.

zachdaniel

zachdaniel

Creator of Ash

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

— All posts loaded —

Where Next? Top

Trending in Questions Top

itzmidinesh
Hi all, I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
yarrichar
I’m very new to Elixir, so sorry if this is a silly question: I am wondering what happens to the mailbox of a process when the machine i...
New
pragdave
How do I tell Hologram not to escape HTML when substituting into templates? {Textile.render(@product.long_description)} escapes the HTM...
New
Fl4m3Ph03n1x
Background When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error: * assembling mark...
New
rlipscombe
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
saleyn
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
rlipscombe
When I use Mix.install with a git dependency, using git@github.com:... how do I change the SSH identity used? I’ve got two Github accoun...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
raa-ziq
Hi everyone :waving_hand: I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews