Adding a embedded resource to a resource is failing

I have this embedded resource:
defmodule Marketplace.Markets.Property.Image do
use Ash.Resource,
data_layer: :embedded,
extensions: [AshGraphql.Resource]

code_interface do
define_for Marketplace.Markets

define :new
end

actions do
create :new, primary?: true
end

attributes do
attribute :uuid, :uuid, allow_nil?: false

attribute :category, :atom do
constraints one_of: [:bedroom, :bathroom]
end

attribute :description, :string
end

graphql do
type :image
end
end
defmodule Marketplace.Markets.Property.Image do
use Ash.Resource,
data_layer: :embedded,
extensions: [AshGraphql.Resource]

code_interface do
define_for Marketplace.Markets

define :new
end

actions do
create :new, primary?: true
end

attributes do
attribute :uuid, :uuid, allow_nil?: false

attribute :category, :atom do
constraints one_of: [:bedroom, :bathroom]
end

attribute :description, :string
end

graphql do
type :image
end
end
I'm trying to use it inside another resource:
attribute :images, {:array, Marketplace.Markets.Property.Image}, default: []
attribute :images, {:array, Marketplace.Markets.Property.Image}, default: []
But I'm getting the following error:
== Compilation error in file lib/marketplace/markets/property.ex ==
** (RuntimeError) {:array, Marketplace.Markets.Property.Image} is not a valid type.

Valid types include any custom types, or the following short codes (alongside the types they map to):

:map -> Ash.Type.Map
:term -> Ash.Type.Term
:atom -> Ash.Type.Atom
:string -> Ash.Type.String
:integer -> Ash.Type.Integer
:float -> Ash.Type.Float
:duration_name -> Ash.Type.DurationName
:function -> Ash.Type.Function
:boolean -> Ash.Type.Boolean
:struct -> Ash.Type.Struct
:uuid -> Ash.Type.UUID
:binary -> Ash.Type.Binary
:date -> Ash.Type.Date
:time -> Ash.Type.Time
:decimal -> Ash.Type.Decimal
:ci_string -> Ash.Type.CiString
:naive_datetime -> Ash.Type.NaiveDatetime
:utc_datetime -> Ash.Type.UtcDatetime
:utc_datetime_usec -> Ash.Type.UtcDatetimeUsec
:url_encoded_binary -> Ash.Type.UrlEncodedBinary
:union -> Ash.Type.Union


(ash 2.6.17) lib/ash/type/type.ex:928: Ash.Type.set_type_transformation/1
lib/marketplace/markets/property.ex:163: (module)
== Compilation error in file lib/marketplace/markets/property.ex ==
** (RuntimeError) {:array, Marketplace.Markets.Property.Image} is not a valid type.

Valid types include any custom types, or the following short codes (alongside the types they map to):

:map -> Ash.Type.Map
:term -> Ash.Type.Term
:atom -> Ash.Type.Atom
:string -> Ash.Type.String
:integer -> Ash.Type.Integer
:float -> Ash.Type.Float
:duration_name -> Ash.Type.DurationName
:function -> Ash.Type.Function
:boolean -> Ash.Type.Boolean
:struct -> Ash.Type.Struct
:uuid -> Ash.Type.UUID
:binary -> Ash.Type.Binary
:date -> Ash.Type.Date
:time -> Ash.Type.Time
:decimal -> Ash.Type.Decimal
:ci_string -> Ash.Type.CiString
:naive_datetime -> Ash.Type.NaiveDatetime
:utc_datetime -> Ash.Type.UtcDatetime
:utc_datetime_usec -> Ash.Type.UtcDatetimeUsec
:url_encoded_binary -> Ash.Type.UrlEncodedBinary
:union -> Ash.Type.Union


(ash 2.6.17) lib/ash/type/type.ex:928: Ash.Type.set_type_transformation/1
lib/marketplace/markets/property.ex:163: (module)
7 Replies
ZachDaniel
ZachDaniel3y ago
Have you defined them in the same file?
Blibs
BlibsOP3y ago
No, they are in separated files Ah, but I did create another embedded resource inside the same file as the Image embedded resource
ZachDaniel
ZachDaniel3y ago
Try moving them to separate files and see if that helps
Blibs
BlibsOP3y ago
Yeah, that solves the problem
ZachDaniel
ZachDaniel3y ago
Not much ash can do about module dependencies like that
Blibs
BlibsOP3y ago
Do we have somewhere in the docs saying that you can't create more than one embedded resource in the same file?
ZachDaniel
ZachDaniel3y ago
I don't think so, although its not necessarily the case that you can't do that but some configurations will be problematic because of compile time dependencies on modules in the same file But we could put a note to this effect in the embedded resource guide to point people in the right direction. i.e just advise that they use separate files for each embedded resource.

Did you find this page helpful?