diff --git a/lib/ash_graphql.ex b/lib/ash_graphql.ex index d52460b..57ca2a1 100644 --- a/lib/ash_graphql.ex +++ b/lib/ash_graphql.ex @@ -680,13 +680,27 @@ defmodule AshGraphql do } case attribute.type do - Ash.Type.Map -> - if attribute.constraints[:fields] do - {source_resource, attribute} + type when type in [Ash.Type.Map, Ash.Type.Keyword, Ash.Type.Struct] -> + if fields = attribute.constraints[:fields] do + Enum.flat_map(fields, fn {name, config} -> + if AshGraphql.Resource.embedded?(config[:type]) do + [ + {source_resource, + %{ + attribute + | type: config[:type], + constraints: config[:constraints], + name: :"#{attribute.name}_#{name}" + }} + ] + else + [] + end + end) + else + [] end - [] - Ash.Type.Union -> attribute.constraints[:types] |> Kernel.||([]) diff --git a/lib/resource/resource.ex b/lib/resource/resource.ex index ad348d9..c0d642a 100644 --- a/lib/resource/resource.ex +++ b/lib/resource/resource.ex @@ -2979,9 +2979,14 @@ defmodule AshGraphql.Resource do {types, fields} = Enum.reduce(constraints[:fields] || [], {[], []}, fn {name, attribute}, {types, fields} -> map_type? = - attribute[:type] in [:map, Ash.Type.Map] || + attribute[:type] in [:map, Ash.Type.Map, :struct, Ash.Type.Struct] || (Ash.Type.NewType.new_type?(attribute[:type]) && - Ash.Type.NewType.subtype_of(attribute[:type]) in [:map, Ash.Type.Map]) + Ash.Type.NewType.subtype_of(attribute[:type]) in [ + :map, + Ash.Type.Map, + :struct, + Ash.Type.Struct + ]) if map_type? && attribute[:constraints] not in [nil, []] do nested_type_name =