Skip to content

Commit

Permalink
improvement: support map w/ keys _union_type and _union_value for…
Browse files Browse the repository at this point in the history
… union inputs
  • Loading branch information
zachdaniel committed Nov 5, 2024
1 parent 1eae227 commit 5cb05d4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/ash/type/union.ex
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,18 @@ defmodule Ash.Type.Union do
end
end

def cast_input(%{"_union_type" => union_type, "_union_value" => value}, constraints) do
case Enum.find(constraints[:types], fn {key, _} ->
to_string(key) == union_type
end) do
{type, _config} ->
cast_input(%Ash.Union{value: value, type: type}, constraints)

_ ->
cast_input(Map.delete(value, "_union_type"), constraints)
end
end

def cast_input(%{"_union_type" => union_type} = value, constraints) do
case Enum.find(constraints[:types], fn {key, _} ->
to_string(key) == union_type
Expand Down

0 comments on commit 5cb05d4

Please sign in to comment.