zf

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

data.ex (1476B)


      1 defmodule Absinthe.Phase.Schema.Arguments.Data do
      2   @moduledoc false
      3 
      4   # Populate all arguments in the SDL with their provided data values.
      5   #
      6   # See Absinthe.Phase.Document.Arguments.Data for a more expansive
      7   # explanation; this phase limits itself to arguments and values.
      8 
      9   alias Absinthe.Blueprint.Input
     10   alias Absinthe.{Blueprint}
     11   use Absinthe.Phase
     12 
     13   def run(input, _options \\ []) do
     14     # By using a postwalk we can worry about leaf nodes first (scalars, enums),
     15     # and then for list and objects merely grab the data values.
     16     result = Blueprint.postwalk(input, &handle_node/1)
     17     {:ok, result}
     18   end
     19 
     20   def handle_node(%Input.Argument{input_value: input} = node) do
     21     %{node | value: input.data}
     22   end
     23 
     24   def handle_node(%Input.Value{normalized: %Input.List{items: items}} = node) do
     25     data_list = for %{data: data} = item <- items, Input.Value.valid?(item), do: data
     26     %{node | data: data_list}
     27   end
     28 
     29   def handle_node(%Input.Value{normalized: %Input.Object{fields: fields}} = node) do
     30     data =
     31       for field <- fields, include_field?(field), into: %{} do
     32         {field.schema_node.identifier, field.input_value.data}
     33       end
     34 
     35     %{node | data: data}
     36   end
     37 
     38   def handle_node(node) do
     39     node
     40   end
     41 
     42   defp include_field?(%{input_value: %{normalized: %Input.Null{}}}), do: true
     43   defp include_field?(%{input_value: %{data: nil}}), do: false
     44   defp include_field?(%{schema_node: nil}), do: false
     45   defp include_field?(_), do: true
     46 end