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.



289
290
291
292
# File 'lib/graph_weaver/codegen/nodes.rb', line 289

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

Instance Attribute Details

#class_nameObject (readonly)

Returns the value of attribute class_name.



287
288
289
# File 'lib/graph_weaver/codegen/nodes.rb', line 287

def class_name
  @class_name
end

#fieldsObject (readonly)

Returns the value of attribute fields.



287
288
289
# File 'lib/graph_weaver/codegen/nodes.rb', line 287

def fields
  @fields
end

Instance Method Details

#bare_typeObject



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

def bare_type = class_name

#cast(_expr, _depth) ⇒ Object

Raises:



300
301
302
# File 'lib/graph_weaver/codegen/nodes.rb', line 300

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

#coerce(expr) ⇒ Object



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

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

#coerce?Boolean

Returns:

  • (Boolean)


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

def coerce? = true

#coerce_input_typeObject



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

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



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

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

#serialize(expr, _depth) ⇒ Object



296
297
298
# File 'lib/graph_weaver/codegen/nodes.rb', line 296

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