Class: GraphWeaver::Codegen::NarrowedNode

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

Overview

A single-condition narrowing of an abstract field (... on Pet { ... } and nothing else): the member struct when the runtime type matches, nil when it doesn't — a non-match's response object carries no matching fields, so the hash arrives empty. Always nilable, whatever the schema's nullability, because narrowing filters.

Instance Method Summary collapse

Methods inherited from Node

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

Constructor Details

#initialize(of) ⇒ NarrowedNode

Returns a new instance of NarrowedNode.



249
250
251
# File 'lib/graph_weaver/codegen/nodes.rb', line 249

def initialize(of)
  @of = of
end

Instance Method Details

#bare_typeObject



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

def bare_type = @of.bare_type

#cast(expr, depth) ⇒ Object



256
257
258
# File 'lib/graph_weaver/codegen/nodes.rb', line 256

def cast(expr, depth)
  "(#{expr}.empty? ? nil : #{@of.cast(expr, depth)})"
end

#class_nameObject



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

def class_name = @of.class_name

#nestedObject



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

def nested = @of