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) ⇒ Object
Class Methods ####.
Instance Method Summary collapse
-
#format_nested_attributes ⇒ Object
Recursively format attributes so that they are compatible with ‘accepts_nested_attributes_for`.
- #with_indifferent_access ⇒ Object
Methods included from ActiveRecordExtensions
Class Method Details
.nested_attributes ⇒ Object
52 53 54 |
# File 'lib/hq/graphql/input_object.rb', line 52 def self.nested_attributes @nested_attributes ||= Set.new end |
.to_graphql ⇒ Object
56 57 58 59 |
# File 'lib/hq/graphql/input_object.rb', line 56 def self.to_graphql lazy_load! super end |
.with_model(model_name, attributes: true, associations: false) ⇒ Object
Class Methods ####
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/hq/graphql/input_object.rb', line 34 def self.with_model(model_name, attributes: true, associations: false) self.model_name = model_name self.auto_load_attributes = attributes self.auto_load_associations = associations 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`
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/hq/graphql/input_object.rb', line 8 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 |
#with_indifferent_access ⇒ Object
28 29 30 |
# File 'lib/hq/graphql/input_object.rb', line 28 def with_indifferent_access to_h.with_indifferent_access end |