Class: HQ::GraphQL::InputObject
- Inherits:
-
GraphQL::Schema::InputObject
- Object
- GraphQL::Schema::InputObject
- HQ::GraphQL::InputObject
- Includes:
- ActiveRecordExtensions, Scalars
- Defined in:
- lib/hq/graphql/input_object.rb
Constant Summary
Constants included from Scalars
Scalars::Object, Scalars::UUID
Class Method Summary collapse
- .nested_attributes ⇒ Object
- .to_graphql ⇒ Object
-
.with_model(model_name, attributes: true, associations: false, enums: true) ⇒ Object
Class Methods ####.
Instance Method Summary collapse
-
#format_nested_attributes ⇒ Object
Recursively format attributes so that they are compatible with ‘accepts_nested_attributes_for`.
Methods included from ActiveRecordExtensions
Class Method Details
.nested_attributes ⇒ Object
54 55 56 |
# File 'lib/hq/graphql/input_object.rb', line 54 def self.nested_attributes @nested_attributes ||= Set.new end |
.to_graphql ⇒ Object
58 59 60 61 |
# File 'lib/hq/graphql/input_object.rb', line 58 def self.to_graphql lazy_load! super end |
.with_model(model_name, attributes: true, associations: false, enums: true) ⇒ Object
Class Methods ####
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/hq/graphql/input_object.rb', line 35 def self.with_model(model_name, attributes: true, associations: false, enums: true) self.model_name = model_name self.auto_load_attributes = attributes self.auto_load_associations = associations self.auto_load_enums = enums lazy_load do model_columns.each do |column| argument_from_column(column) end model_associations.each do |association| argument_from_association association end argument :X, String, required: false end end |
Instance Method Details
#format_nested_attributes ⇒ Object
Recursively format attributes so that they are compatible with ‘accepts_nested_attributes_for`
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/hq/graphql/input_object.rb', line 14 def format_nested_attributes self.each.inject({}) do |formatted_attrs, (key, value) | if self.class.nested_attributes.include?(key.to_s) formatted_value = if value.is_a?(Array) value.map(&:format_nested_attributes) elsif value value.format_nested_attributes end formatted_attrs[:"#{key}_attributes"] = formatted_value if formatted_value elsif key.to_s == "x" formatted_attrs[:X] = value else formatted_attrs[key] = value end formatted_attrs end end |