zf

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

directive.ex (2478B)


      1 defmodule Absinthe.Blueprint.Directive do
      2   @moduledoc false
      3 
      4   alias Absinthe.{Blueprint, Phase}
      5 
      6   @enforce_keys [:name]
      7   defstruct [
      8     :name,
      9     arguments: [],
     10     # When part of a Document
     11     source_location: nil,
     12     # Added by phases
     13     schema_node: nil,
     14     flags: %{},
     15     errors: [],
     16     __reference__: nil,
     17     __private__: []
     18   ]
     19 
     20   @type t :: %__MODULE__{
     21           name: String.t(),
     22           arguments: [Blueprint.Input.Argument.t()],
     23           source_location: nil | Blueprint.SourceLocation.t(),
     24           schema_node: nil | Absinthe.Type.Directive.t(),
     25           flags: Blueprint.flags_t(),
     26           errors: [Phase.Error.t()],
     27           __reference__: nil,
     28           __private__: []
     29         }
     30 
     31   @spec expand(t, Blueprint.node_t()) :: {t, map}
     32   def expand(%__MODULE__{schema_node: nil}, node) do
     33     node
     34   end
     35 
     36   def expand(%__MODULE__{schema_node: type} = directive, node) do
     37     args = Blueprint.Input.Argument.value_map(directive.arguments)
     38 
     39     case Absinthe.Type.function(type, :expand) do
     40       nil ->
     41         # Directive is a no-op
     42         node
     43 
     44       expansion when is_function(expansion) ->
     45         expansion.(args, node)
     46     end
     47   end
     48 
     49   @doc """
     50   Determine the placement name for a given Blueprint node
     51   """
     52   @spec placement(Blueprint.node_t()) :: nil | atom
     53   def placement(%Blueprint.Document.Operation{type: type}), do: type
     54   def placement(%Blueprint.Document.Field{}), do: :field
     55   def placement(%Blueprint.Document.Fragment.Named{}), do: :fragment_definition
     56   def placement(%Blueprint.Document.Fragment.Spread{}), do: :fragment_spread
     57   def placement(%Blueprint.Document.Fragment.Inline{}), do: :inline_fragment
     58   def placement(%Blueprint.Schema.SchemaDefinition{}), do: :schema
     59   def placement(%Blueprint.Schema.SchemaDeclaration{}), do: :schema
     60   def placement(%Blueprint.Schema.ScalarTypeDefinition{}), do: :scalar
     61   def placement(%Blueprint.Schema.ObjectTypeDefinition{}), do: :object
     62   def placement(%Blueprint.Schema.FieldDefinition{}), do: :field_definition
     63   def placement(%Blueprint.Schema.InterfaceTypeDefinition{}), do: :interface
     64   def placement(%Blueprint.Schema.UnionTypeDefinition{}), do: :union
     65   def placement(%Blueprint.Schema.EnumTypeDefinition{}), do: :enum
     66   def placement(%Blueprint.Schema.EnumValueDefinition{}), do: :enum_value
     67   def placement(%Blueprint.Schema.InputObjectTypeDefinition{}), do: :input_object
     68   def placement(%Blueprint.Schema.InputValueDefinition{placement: placement}), do: placement
     69 end