zf

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

current_operation.ex (1030B)


      1 defmodule Absinthe.Phase.Document.CurrentOperation do
      2   @moduledoc false
      3 
      4   # Selects the current operation.
      5   #
      6   # - If an operation name is given, the matching operation is marked as current.
      7   # - If no operation name is provided and the there is only one operation,
      8   #   it is set as current.
      9   #
     10   # Note that no validation occurs in this phase.
     11 
     12   use Absinthe.Phase
     13   alias Absinthe.Blueprint
     14 
     15   @spec run(Blueprint.t(), Keyword.t()) :: {:ok, Blueprint.t()}
     16   def run(input, options \\ []) do
     17     operations = process(input.operations, Map.new(options))
     18     result = %{input | operations: operations}
     19     {:ok, result}
     20   end
     21 
     22   defp process([op], %{operation_name: nil}) do
     23     [%{op | current: true}]
     24   end
     25 
     26   defp process([%{name: name} = op], %{operation_name: name}) do
     27     [%{op | current: true}]
     28   end
     29 
     30   defp process(ops, %{operation_name: name}) do
     31     Enum.map(ops, fn
     32       %{name: ^name} = op ->
     33         %{op | current: true}
     34 
     35       op ->
     36         op
     37     end)
     38   end
     39 
     40   defp process(ops, _) do
     41     ops
     42   end
     43 end