Class: SolidusGraphqlApi::BatchLoader
- Inherits:
-
Object
- Object
- SolidusGraphqlApi::BatchLoader
- Defined in:
- lib/solidus_graphql_api/batch_loader.rb,
lib/solidus_graphql_api/batch_loader/has_one.rb,
lib/solidus_graphql_api/batch_loader/has_many.rb,
lib/solidus_graphql_api/batch_loader/belongs_to.rb,
lib/solidus_graphql_api/batch_loader/has_many_through.rb
Overview
Provides an abstraction layer on top of BatchLoader::GraphQL
that removes all the boilerplate normally needed to batch-load ActiveRecord associations.
Direct Known Subclasses
Defined Under Namespace
Classes: BelongsTo, HasMany, HasManyThrough, HasOne
Constant Summary collapse
- LOADER_CLASSES =
{ has_one: BatchLoader::HasOne, has_many: BatchLoader::HasMany, has_many_through: BatchLoader::HasManyThrough, belongs_to: BatchLoader::BelongsTo, }.freeze
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#reflection ⇒ Object
readonly
Returns the value of attribute reflection.
Class Method Summary collapse
-
.for(object, association, options = {}) ⇒ BatchLoader::GraphQL
Generates the batch loader for an ActiveRecord instance-association pair.
Instance Method Summary collapse
-
#initialize(object, reflection, options = {}) ⇒ BatchLoader
constructor
Generates a new instance of this batch loader for an ActiveRecord instance-association pair.
-
#load ⇒ BatchLoader::GraphQL
Returns the batch loading logic.
Constructor Details
#initialize(object, reflection, options = {}) ⇒ BatchLoader
Generates a new instance of this batch loader for an ActiveRecord instance-association pair.
68 69 70 71 72 |
# File 'lib/solidus_graphql_api/batch_loader.rb', line 68 def initialize(object, reflection, = {}) @object = object @reflection = reflection @options = end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
58 59 60 |
# File 'lib/solidus_graphql_api/batch_loader.rb', line 58 def object @object end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
58 59 60 |
# File 'lib/solidus_graphql_api/batch_loader.rb', line 58 def @options end |
#reflection ⇒ Object (readonly)
Returns the value of attribute reflection.
58 59 60 |
# File 'lib/solidus_graphql_api/batch_loader.rb', line 58 def reflection @reflection end |
Class Method Details
.for(object, association, options = {}) ⇒ BatchLoader::GraphQL
Generates the batch loader for an ActiveRecord instance-association pair.
29 30 31 32 |
# File 'lib/solidus_graphql_api/batch_loader.rb', line 29 def for(object, association, = {}) reflection = object.class.reflect_on_association(association) loader_class_for(reflection).new(object, reflection, ).load end |
Instance Method Details
#load ⇒ BatchLoader::GraphQL
Returns the batch loading logic.
77 78 79 |
# File 'lib/solidus_graphql_api/batch_loader.rb', line 77 def load raise NotImplementedError end |