zf

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

http_method.ex (567B)


      1 defmodule Absinthe.Plug.Validation.HTTPMethod do
      2   @moduledoc false
      3 
      4   use Absinthe.Phase
      5 
      6   alias Absinthe.Blueprint
      7 
      8   @post_only [:mutation]
      9 
     10   def run(blueprint, options) do
     11     do_run(blueprint, Map.new(options))
     12   end
     13 
     14   defp do_run(blueprint, %{method: "POST"}) do
     15     {:ok, blueprint}
     16   end
     17 
     18   defp do_run(blueprint, _) do
     19     case Blueprint.current_operation(blueprint) do
     20       %{type: type} when type in @post_only ->
     21         {:error, {:http_method, "Can only perform a #{type} from a POST request"}}
     22 
     23       _ ->
     24         {:ok, blueprint}
     25     end
     26   end
     27 end