zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

result.ex (938B)


      1 defmodule Absinthe.Phase.Schema.Validation.Result do
      2   @moduledoc false
      3 
      4   alias Absinthe.{Blueprint, Phase}
      5 
      6   use Absinthe.Phase
      7 
      8   @doc """
      9   Run the validation.
     10   """
     11   @spec run(Blueprint.t(), Keyword.t()) :: Phase.result_t()
     12   def run(input, _opts) do
     13     {input, errors} = Blueprint.prewalk(input, [], &handle_node/2)
     14     errors = errors |> :lists.reverse() |> Enum.uniq()
     15 
     16     case errors do
     17       [] ->
     18         {:ok, input}
     19 
     20       _ ->
     21         {:error, errors}
     22     end
     23   end
     24 
     25   # Collect the validation errors from nodes
     26   @spec handle_node(Blueprint.node_t(), [Phase.Error.t()]) ::
     27           {Blueprint.node_t(), [Phase.Error.t()]}
     28   defp handle_node(%{errors: errs} = node, errors) do
     29     {node, :lists.reverse(errs) ++ errors}
     30   end
     31 
     32   defp handle_node(%{raw: raw} = node, errors) do
     33     {_, errors} = Blueprint.prewalk(raw, errors, &handle_node/2)
     34     {node, errors}
     35   end
     36 
     37   defp handle_node(node, acc), do: {node, acc}
     38 end