mirror of
https://github.com/ash-project/ash_graphql.git
synced 2024-09-19 12:53:40 +12:00
improvement: support new struct fields constraint
This commit is contained in:
parent
b79cd6c562
commit
190a7a1f75
2 changed files with 26 additions and 7 deletions
|
@ -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.||([])
|
||||
|
|
|
@ -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 =
|
||||
|
|
Loading…
Reference in a new issue