value.ex (1188B)
1 defmodule Absinthe.Blueprint.Input.Value do 2 @moduledoc false 3 4 # An input in a document. 5 # 6 # Used by arguments, input object fields, and input lists. 7 8 @enforce_keys [:raw, :normalized] 9 defstruct [ 10 :schema_node, 11 :raw, 12 :normalized, 13 :data 14 ] 15 16 alias Absinthe.Blueprint.Input 17 18 @type variable :: Input.Variable.t() 19 @type literals :: 20 Input.Integer.t() 21 | Input.Float.t() 22 | Input.Enum.t() 23 | Input.String.t() 24 | Input.Boolean.t() 25 | Input.List.t() 26 | Input.Object.t() 27 | variable 28 29 @type t :: %__MODULE__{ 30 raw: Input.RawValue.t(), 31 normalized: literals, 32 data: term 33 } 34 35 @spec valid?(t) :: boolean 36 @doc false 37 # Whether a value is valid and useful in an argument 38 def valid?(%{normalized: %Absinthe.Blueprint.Input.Null{}}), do: true 39 def valid?(%{normalized: nil}), do: false 40 def valid?(%{normalized: _}), do: true 41 42 def build(value) do 43 %Absinthe.Blueprint.Input.Value{ 44 data: value, 45 normalized: nil, 46 raw: %Absinthe.Blueprint.Input.RawValue{ 47 content: Absinthe.Blueprint.Input.parse(value) 48 } 49 } 50 end 51 end