Class: GraphQL::Rails::ActiveReflection::ModelReflection

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/rails/active_reflection/model_reflection.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, schema) ⇒ ModelReflection

Returns a new instance of ModelReflection.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/graphql/rails/active_reflection/model_reflection.rb', line 14

def initialize(klass, schema)
  @klass = klass
  @type = schema.resolve_type(@klass)
  @schema = schema
  @attributes = @type.fields.map { |field|
    # No reflection if it's not a model attribute
    property = field.property || field.name
    return nil unless klass.attribute_names.include? property

    AttributeReflection.new(field, klass, schema)
  }.compact
end

Class Attribute Details

.schema_nameObject

Returns the value of attribute schema_name.



28
29
30
# File 'lib/graphql/rails/active_reflection/model_reflection.rb', line 28

def schema_name
  @schema_name
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



12
13
14
# File 'lib/graphql/rails/active_reflection/model_reflection.rb', line 12

def attributes
  @attributes
end

Class Method Details

.call(obj, args, ctx) ⇒ Object

Raises:



7
8
9
10
# File 'lib/graphql/rails/active_reflection/model_reflection.rb', line 7

def self.call(obj, args, ctx)
  raise UnsupportedObject unless obj < ActiveRecord::Base
  @reflections[obj.class] ||= new(obj.class, ctx.schema)
end