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

water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Alvinkariuki
How Can I Optimise Compile Time Dependencies I have been building an elixir application for about 2 years now. Many modules and files ha...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New

Other Trending Topics Top

budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
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
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews