sezaru
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.
Marked As Solved
zachdaniel
Creator of Ash
Popular in Questions
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
Hello, how can I check the Phoenix version ?
Thanks !
New
I have VueJS GUIs with the project generated using Webpack.
I have Elixir modules that will need to be used by the VueJS GUIs.
I forese...
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
Other popular topics
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
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
New
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
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something…
Haskell reminds me of Java, and e...
New
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
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









