`Ash.Type.NewType` defines multiple GraphQL types with the same name.
I have the following custom type
That is used in two resources
Also I've defined a Scalar and imported it to schema
defmodule MyApp.Types.DayOfWeek do
@moduledoc false
use Ash.Type.NewType,
subtype_of: :atom,
constraints: [one_of: [:monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday]]
def graphql_input_type(_), do: :day_of_week
def graphql_type, do: :day_of_week
def graphql_type(_), do: :day_of_week
enddefmodule MyApp.Types.DayOfWeek do
@moduledoc false
use Ash.Type.NewType,
subtype_of: :atom,
constraints: [one_of: [:monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday]]
def graphql_input_type(_), do: :day_of_week
def graphql_type, do: :day_of_week
def graphql_type(_), do: :day_of_week
endThat is used in two resources
defmodule ResourceA do
...
attributes do
...
attribute :days_of_week, {:array, MyApp.Types.DayOfWeek}
end
end
defmodule ResourceB do
...
attributes do
...
attribute :day_of_week, MyApp.Types.DayOfWeek}
end
relationships do
belongs_to :a_resource, ResourceA, allow_nil?: false
end
enddefmodule ResourceA do
...
attributes do
...
attribute :days_of_week, {:array, MyApp.Types.DayOfWeek}
end
end
defmodule ResourceB do
...
attributes do
...
attribute :day_of_week, MyApp.Types.DayOfWeek}
end
relationships do
belongs_to :a_resource, ResourceA, allow_nil?: false
end
endAlso I've defined a Scalar and imported it to schema
scalar :day_of_week do
parse(&parse_day_of_week/1)
serialize(& &1)
end
defp parse_day_of_week(%Absinthe.Blueprint.Input.String{value: value}) do
case MyApp.Types.DayOfWeek.cast_input(value, []) do
{:ok, value} -> {:ok, value}
_ -> :error
end
end scalar :day_of_week do
parse(&parse_day_of_week/1)
serialize(& &1)
end
defp parse_day_of_week(%Absinthe.Blueprint.Input.String{value: value}) do
case MyApp.Types.DayOfWeek.cast_input(value, []) do
{:ok, value} -> {:ok, value}
_ -> :error
end
end