mirror of
https://github.com/ash-project/ash_graphql.git
synced 2024-09-20 05:13:33 +12:00
fix: don't generate duplicate types
This commit is contained in:
parent
378892e387
commit
b2b9e22f7c
1 changed files with 42 additions and 38 deletions
|
@ -1945,54 +1945,58 @@ defmodule AshGraphql.Resource do
|
||||||
end
|
end
|
||||||
|
|
||||||
def enum_definitions(resource, schema, env, only_auto? \\ false) do
|
def enum_definitions(resource, schema, env, only_auto? \\ false) do
|
||||||
atom_enums =
|
if AshGraphql.Resource.Info.type(resource) do
|
||||||
resource
|
atom_enums =
|
||||||
|> get_auto_enums()
|
resource
|
||||||
|> Enum.filter(&is_list(&1.constraints[:one_of]))
|
|> get_auto_enums()
|
||||||
|> Enum.map(fn attribute ->
|
|> Enum.filter(&is_list(&1.constraints[:one_of]))
|
||||||
type_name = atom_enum_type(resource, attribute.name)
|
|> Enum.map(fn attribute ->
|
||||||
|
type_name = atom_enum_type(resource, attribute.name)
|
||||||
|
|
||||||
%Absinthe.Blueprint.Schema.EnumTypeDefinition{
|
%Absinthe.Blueprint.Schema.EnumTypeDefinition{
|
||||||
|
module: schema,
|
||||||
|
name: type_name |> to_string() |> Macro.camelize(),
|
||||||
|
values:
|
||||||
|
Enum.map(attribute.constraints[:one_of], fn value ->
|
||||||
|
%Absinthe.Blueprint.Schema.EnumValueDefinition{
|
||||||
|
module: schema,
|
||||||
|
identifier: value,
|
||||||
|
__reference__: AshGraphql.Resource.ref(env),
|
||||||
|
name: String.upcase(to_string(value)),
|
||||||
|
value: value
|
||||||
|
}
|
||||||
|
end),
|
||||||
|
identifier: type_name,
|
||||||
|
__reference__: ref(__ENV__)
|
||||||
|
}
|
||||||
|
end)
|
||||||
|
|
||||||
|
if only_auto? do
|
||||||
|
atom_enums
|
||||||
|
else
|
||||||
|
sort_values = sort_values(resource)
|
||||||
|
|
||||||
|
sort_order = %Absinthe.Blueprint.Schema.EnumTypeDefinition{
|
||||||
module: schema,
|
module: schema,
|
||||||
name: type_name |> to_string() |> Macro.camelize(),
|
name: resource |> resource_sort_field_type() |> to_string() |> Macro.camelize(),
|
||||||
|
identifier: resource_sort_field_type(resource),
|
||||||
|
__reference__: ref(__ENV__),
|
||||||
values:
|
values:
|
||||||
Enum.map(attribute.constraints[:one_of], fn value ->
|
Enum.map(sort_values, fn sort_value ->
|
||||||
%Absinthe.Blueprint.Schema.EnumValueDefinition{
|
%Absinthe.Blueprint.Schema.EnumValueDefinition{
|
||||||
module: schema,
|
module: schema,
|
||||||
identifier: value,
|
identifier: sort_value,
|
||||||
__reference__: AshGraphql.Resource.ref(env),
|
__reference__: AshGraphql.Resource.ref(env),
|
||||||
name: String.upcase(to_string(value)),
|
name: String.upcase(to_string(sort_value)),
|
||||||
value: value
|
value: sort_value
|
||||||
}
|
}
|
||||||
end),
|
end)
|
||||||
identifier: type_name,
|
|
||||||
__reference__: ref(__ENV__)
|
|
||||||
}
|
}
|
||||||
end)
|
|
||||||
|
|
||||||
if only_auto? do
|
[sort_order | atom_enums]
|
||||||
atom_enums
|
end
|
||||||
else
|
else
|
||||||
sort_values = sort_values(resource)
|
[]
|
||||||
|
|
||||||
sort_order = %Absinthe.Blueprint.Schema.EnumTypeDefinition{
|
|
||||||
module: schema,
|
|
||||||
name: resource |> resource_sort_field_type() |> to_string() |> Macro.camelize(),
|
|
||||||
identifier: resource_sort_field_type(resource),
|
|
||||||
__reference__: ref(__ENV__),
|
|
||||||
values:
|
|
||||||
Enum.map(sort_values, fn sort_value ->
|
|
||||||
%Absinthe.Blueprint.Schema.EnumValueDefinition{
|
|
||||||
module: schema,
|
|
||||||
identifier: sort_value,
|
|
||||||
__reference__: AshGraphql.Resource.ref(env),
|
|
||||||
name: String.upcase(to_string(sort_value)),
|
|
||||||
value: sort_value
|
|
||||||
}
|
|
||||||
end)
|
|
||||||
}
|
|
||||||
|
|
||||||
[sort_order | atom_enums]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue