Class: GraphWeaver::Codegen::NarrowedNode

Inherits:
Object
  • 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

Constructor Details

#initialize(of) ⇒ NarrowedNode

Returns a new instance of NarrowedNode.



271
272
273
# File 'lib/graph_weaver/codegen/nodes.rb', line 271

def initialize(of)
  @of = of
end

Instance Method Details

#bare_type ⇒ Object



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

def bare_type = @of.bare_type

#cast(expr, depth) ⇒ Object



282
283
284
# File 'lib/graph_weaver/codegen/nodes.rb', line 282

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

#class_name ⇒ Object



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

def class_name = @of.class_name

#identity? ⇒ Boolean

Returns:

  • (Boolean)


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

def identity? = false

#nested ⇒ Object



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

def nested = @of

#non_null? ⇒ Boolean

Returns:

  • (Boolean)


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

def non_null? = false

#prop_type ⇒ Object



278
279
280
# File 'lib/graph_weaver/codegen/nodes.rb', line 278

def prop_type
  "T.nilable(#{bare_type})"
end