Module: HQ::GraphQL::Ext::ObjectExtensions::PrependMethods

Defined in:
lib/hq/graphql/ext/object_extensions.rb

Instance Method Summary collapse

Instance Method Details

#authorize_action(action) ⇒ Object



24
25
26
# File 'lib/hq/graphql/ext/object_extensions.rb', line 24

def authorize_action(action)
  self.authorized_action = action
end

#authorized?(object, context) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/hq/graphql/ext/object_extensions.rb', line 28

def authorized?(object, context)
  super && ::HQ::GraphQL.authorized?(authorized_action, object, context)
end

#with_model(model_name, attributes: true, associations: true, auto_nil: true, enums: true) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/hq/graphql/ext/object_extensions.rb', line 32

def with_model(model_name, attributes: true, associations: true, auto_nil: true, 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|
      field_from_column(column, auto_nil: auto_nil)
    end

    model_associations.each do |association|
      next if resource_reflections[association.name.to_s]
      field_from_association(association, auto_nil: auto_nil)
    end

    resource_reflections.values.each do |resource_reflection|
      reflection = resource_reflection.reflection(model_klass)
      next unless reflection
      field_from_association(reflection, auto_nil: auto_nil, internal_association: true, &resource_reflection.block)
    end
  end
end