Class: GraphWeaver::Codegen::InputNode

Inherits:
Node
  • Object
show all
Defined in:
lib/graph_weaver/codegen/nodes.rb

Overview

An input-object variable: emitted as a module-level T::Struct whose serialize produces the wire hash. Inputs never cast FROM the wire. Joins the coerce protocol so execute kwargs accept plain hashes, normalized (and type-checked) through the generated .coerce.

Defined Under Namespace

Classes: Field

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#hash_coerce_identity?, #identity?, #nested, #non_null?, #prop_type, #serialize_identity?

Constructor Details

#initialize(class_name) ⇒ InputNode

Returns a new instance of InputNode.



313
314
315
316
# File 'lib/graph_weaver/codegen/nodes.rb', line 313

def initialize(class_name)
  @class_name = class_name
  @fields = []
end

Instance Attribute Details

#class_nameObject (readonly)

Returns the value of attribute class_name.



311
312
313
# File 'lib/graph_weaver/codegen/nodes.rb', line 311

def class_name
  @class_name
end

#fieldsObject (readonly)

Returns the value of attribute fields.



311
312
313
# File 'lib/graph_weaver/codegen/nodes.rb', line 311

def fields
  @fields
end

Instance Method Details

#bare_typeObject



318
# File 'lib/graph_weaver/codegen/nodes.rb', line 318

def bare_type = class_name

#cast(_expr, _depth) ⇒ Object

Raises:



324
325
326
# File 'lib/graph_weaver/codegen/nodes.rb', line 324

def cast(_expr, _depth)
  raise GraphWeaver::Error, "input objects are never cast from responses"
end

#coerce(expr) ⇒ Object



329
# File 'lib/graph_weaver/codegen/nodes.rb', line 329

def coerce(expr) = "#{class_name}.coerce(#{expr})"

#coerce?Boolean

Returns:

  • (Boolean)


328
# File 'lib/graph_weaver/codegen/nodes.rb', line 328

def coerce? = true

#coerce_input_typeObject



330
# File 'lib/graph_weaver/codegen/nodes.rb', line 330

def coerce_input_type = "T.any(#{class_name}, T::Hash[T.untyped, T.untyped])"

#hash_coerce(expr, _depth) ⇒ Object

building a struct field from a caller-supplied plain hash value



333
# File 'lib/graph_weaver/codegen/nodes.rb', line 333

def hash_coerce(expr, _depth) = "#{class_name}.coerce(#{expr})"

#serialize(expr, _depth) ⇒ Object



320
321
322
# File 'lib/graph_weaver/codegen/nodes.rb', line 320

def serialize(expr, _depth)
  "#{expr}.serialize"
end