Module: GraphWeaver::InputStruct
- Includes:
- Kernel
- Defined in:
- lib/graph_weaver/input_struct.rb
Overview
Runtime for generated input structs. Each struct declares its typed consts plus a compact FIELDS table — (prop, wire name, requiredness, serializer, coercer) per field, with the conversions emitted as lambdas — and this module is the loop that drives it. One copy here instead of unrolled methods in every struct, which is the difference between ~2 lines and ~6 lines per field when a Hasura bool_exp pulls hundreds of input types into one module.
Defined Under Namespace
Modules: ClassMethods Classes: Field
Class Method Summary collapse
Instance Method Summary collapse
-
#serialize ⇒ Object
(also: #to_h)
the wire hash — optional fields left nil stay off the wire.
Class Method Details
.included(base) ⇒ Object
23 24 25 |
# File 'lib/graph_weaver/input_struct.rb', line 23 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#serialize ⇒ Object Also known as: to_h
the wire hash — optional fields left nil stay off the wire
28 29 30 31 32 33 34 35 |
# File 'lib/graph_weaver/input_struct.rb', line 28 def serialize self.class.const_get(:FIELDS).each_with_object({}) do |field, wire| value = public_send(field.prop) next if value.nil? && !field.required wire[field.wire] = field.serializer && !value.nil? ? field.serializer.call(value) : value end end |