Class: HQ::GraphQL::InputObject

Inherits:
GraphQL::Schema::InputObject
  • Object
show all
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

Instance Method Summary collapse

Methods included from ActiveRecordExtensions

included

Class Method Details

.nested_attributesObject



41
42
43
# File 'lib/hq/graphql/input_object.rb', line 41

def self.nested_attributes
  @nested_attributes ||= Set.new
end

.to_graphqlObject



45
46
47
48
# File 'lib/hq/graphql/input_object.rb', line 45

def self.to_graphql
  lazy_load!
  super
end

.with_model(model_name, attributes: true, associations: false) ⇒ Object

Class Methods ####



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/hq/graphql/input_object.rb', line 25

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
  end
end

Instance Method Details

#format_nested_attributesObject

Recursively format attributes so that they are compatible with ‘accepts_nested_attributes_for`



8
9
10
11
12
13
14
15
16
17
# 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_attrs["#{key}_attributes"] = value.format_nested_attributes
    else
      formatted_attrs[key] = value
    end
    formatted_attrs
  end
end

#with_indifferent_accessObject



19
20
21
# File 'lib/hq/graphql/input_object.rb', line 19

def with_indifferent_access
  to_h.with_indifferent_access
end