How to represent an embedded schema in AshGraphql
I have an existing Ecto schema that has an embedded_field, which itself is backed by an Ecto schema. How do I use the
attributes
DSL to expose this field in my AshGraphql query?
Here's the field in Ecto: embeds_one :details, Details
I tried this in the Ash attributes: attribute :details, :map
, but the GraphQL response had this error: Field "details" must not have a selection since type "JsonString" has no subfields.
4 Replies
Ash has embedded resources, that function in much the same way
That will derive a type for your embedded resource, and when you use that in a resource, i.e
it will assume the proper type
Ah, okay. Thank you.
How do I know when to use
attribute
for this case, and not has_one
?
In Ecto, it would be an embedsone
Does Ash use attribute
in the cases where Ecto uses `embeds*`?Yes, in ash there is no
embeds
concept
Just resources that can behave the same as a type
so data_layer: :embedded
just means "this is an Ash.Type
resource"
and so you can use it in attributesPerfect, thanks!