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(obj, ctx) ⇒ ModelReflection

Returns a new instance of ModelReflection.



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

def initialize(obj, ctx)
  @klass = obj.class
  @type = ctx.schema.resolve_type(obj, ctx)
  @schema = ctx.schema
  @attributes = @type.fields.map { |name, field|
    # No reflection if it's not a model attribute
    property = field.property || name
    if @klass.attribute_names.include? property
      GraphQL::Rails::ActiveReflection::AttributeReflection.new(field, @klass, @schema)
    end
  }.compact
end

Class Attribute Details

.schema_nameObject

Returns the value of attribute schema_name.



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

def schema_name
  @schema_name
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



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

def attributes
  @attributes
end

Class Method Details

.call(obj, args, ctx) ⇒ Object

Raises:

  • (TypeError)


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

def self.call(obj, args, ctx)
  raise TypeError, "ActiveReflection object type must be derived from ActiveRecord::Base" unless obj.is_a?(ActiveRecord::Base)
  @reflections[obj] ||= new(obj, ctx)
end