Class: GraphQL::Rails::ActiveReflection::ModelReflection
- Inherits:
-
Object
- Object
- GraphQL::Rails::ActiveReflection::ModelReflection
- Defined in:
- lib/graphql/rails/active_reflection/model_reflection.rb
Class Attribute Summary collapse
-
.schema_name ⇒ Object
Returns the value of attribute schema_name.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(obj, ctx) ⇒ ModelReflection
constructor
A new instance of ModelReflection.
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_name ⇒ Object
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
#attributes ⇒ Object (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
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 |