Class: ZeroRuby::InputObject
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- ZeroRuby::InputObject
- Includes:
- TypeNames
- Defined in:
- lib/zero_ruby/input_object.rb
Overview
Base class for input objects (nested argument types). Uses Dry::Struct for type coercion and validation.
Includes ZeroRuby::TypeNames for convenient type access via the Types module (e.g., Types::String, Types::ID, Types::Boolean).
Constant Summary
Constants included from TypeNames
Class Method Summary collapse
-
.argument(name, type, description: nil, **_options) ⇒ Object
Alias attribute to argument for DSL compatibility.
-
.argument_descriptions ⇒ Object
Get stored argument descriptions.
-
.arguments_metadata ⇒ Hash<Symbol, Hash>
Returns argument metadata for TypeScript generation.
-
.optional_type?(type) ⇒ Boolean
Check if a type is optional (can accept nil or has a default).
Class Method Details
.argument(name, type, description: nil, **_options) ⇒ Object
Alias attribute to argument for DSL compatibility
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/zero_ruby/input_object.rb', line 46 def argument(name, type, description: nil, **) # Store description for documentation/TypeScript generation argument_descriptions[name.to_sym] = description if description # Use attribute? for optional types (allows key to be omitted) # Use attribute for required types (key must be present) if optional_type?(type) attribute?(name, type) else attribute(name, type) end end |
.argument_descriptions ⇒ Object
Get stored argument descriptions
60 61 62 |
# File 'lib/zero_ruby/input_object.rb', line 60 def argument_descriptions @argument_descriptions ||= {} end |
.arguments_metadata ⇒ Hash<Symbol, Hash>
Returns argument metadata for TypeScript generation
72 73 74 75 76 77 78 79 80 |
# File 'lib/zero_ruby/input_object.rb', line 72 def schema.keys.each_with_object({}) do |key, hash| hash[key.name] = { type: key.type, required: key.required?, name: key.name } end end |
.optional_type?(type) ⇒ Boolean
Check if a type is optional (can accept nil or has a default)
65 66 67 68 |
# File 'lib/zero_ruby/input_object.rb', line 65 def optional_type?(type) return false unless type.respond_to?(:optional?) type.optional? || (type.respond_to?(:default?) && type.default?) end |