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

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
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
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews