zf

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

provided_an_operation.ex (1267B)


      1 defmodule Absinthe.Phase.Document.Validation.ProvidedAnOperation do
      2   @moduledoc false
      3 
      4   # Validates document to ensure that at least one operation is given.
      5 
      6   alias Absinthe.{Blueprint, Phase}
      7 
      8   use Absinthe.Phase
      9   use Absinthe.Phase.Validation
     10 
     11   @doc """
     12   Run the validation.
     13   """
     14   @spec run(Blueprint.t(), Keyword.t()) :: Phase.result_t()
     15   def run(input, options \\ []) do
     16     case {handle_node(input), Map.new(options)} do
     17       {%{flags: %{no_operations: _}} = result,
     18        %{jump_phases: true, validation_result_phase: abort_phase}} ->
     19         {:jump, result, abort_phase}
     20 
     21       {result, _} ->
     22         {:ok, result}
     23     end
     24   end
     25 
     26   # Check for operation without any operations
     27   @spec handle_node(Blueprint.t()) :: Blueprint.t()
     28   defp handle_node(%Blueprint{operations: []} = node) do
     29     node
     30     |> flag_invalid(:no_operations)
     31     |> put_error(error())
     32   end
     33 
     34   defp handle_node(node) do
     35     node
     36   end
     37 
     38   @doc """
     39   Generate an error message for the validation.
     40   """
     41   @spec error_message() :: String.t()
     42   def error_message do
     43     "No operations provided."
     44   end
     45 
     46   # Generate the error for the node
     47   @spec error() :: Phase.Error.t()
     48   defp error do
     49     %Phase.Error{
     50       phase: __MODULE__,
     51       message: error_message()
     52     }
     53   end
     54 end