Class: GraphQL::AssociationBatchResolver::AssociationLoader
- Inherits:
-
Batch::Loader
- Object
- Batch::Loader
- GraphQL::AssociationBatchResolver::AssociationLoader
- Defined in:
- lib/graphql/association_batch_resolver/association_loader.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#association_model ⇒ Object
readonly
Returns the value of attribute association_model.
-
#association_name ⇒ Object
readonly
Returns the value of attribute association_name.
-
#association_primary_key ⇒ Object
readonly
Returns the value of attribute association_primary_key.
-
#bucket ⇒ Object
Returns the value of attribute bucket.
-
#context ⇒ Object
Returns the value of attribute context.
-
#is_collection ⇒ Object
readonly
Returns the value of attribute is_collection.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#model_primary_key ⇒ Object
readonly
Returns the value of attribute model_primary_key.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#scope ⇒ Object
Returns the value of attribute scope.
Class Method Summary collapse
Instance Method Summary collapse
-
#cache_key(record) ⇒ Object
We want to load the associations on all records, even if they have the same id.
-
#initialize(model, association_name, options = {}) ⇒ AssociationLoader
constructor
A new instance of AssociationLoader.
- #load(record) ⇒ Object
- #perform(records) ⇒ Object
Constructor Details
#initialize(model, association_name, options = {}) ⇒ AssociationLoader
Returns a new instance of AssociationLoader.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/graphql/association_batch_resolver/association_loader.rb', line 17 def initialize(model, association_name, = {}) @model = model @association_name = association_name @options = validate @model_primary_key = model.primary_key association = @model.reflect_on_association(association_name) @is_collection = association.collection? @association_model = association.klass @association_primary_key = @association_model.primary_key end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
10 11 12 |
# File 'lib/graphql/association_batch_resolver/association_loader.rb', line 10 def args @args end |
#association_model ⇒ Object (readonly)
Returns the value of attribute association_model.
8 9 10 |
# File 'lib/graphql/association_batch_resolver/association_loader.rb', line 8 def association_model @association_model end |
#association_name ⇒ Object (readonly)
Returns the value of attribute association_name.
8 9 10 |
# File 'lib/graphql/association_batch_resolver/association_loader.rb', line 8 def association_name @association_name end |
#association_primary_key ⇒ Object (readonly)
Returns the value of attribute association_primary_key.
8 9 10 |
# File 'lib/graphql/association_batch_resolver/association_loader.rb', line 8 def association_primary_key @association_primary_key end |
#bucket ⇒ Object
Returns the value of attribute bucket.
10 11 12 |
# File 'lib/graphql/association_batch_resolver/association_loader.rb', line 10 def bucket @bucket end |
#context ⇒ Object
Returns the value of attribute context.
10 11 12 |
# File 'lib/graphql/association_batch_resolver/association_loader.rb', line 10 def context @context end |
#is_collection ⇒ Object (readonly)
Returns the value of attribute is_collection.
8 9 10 |
# File 'lib/graphql/association_batch_resolver/association_loader.rb', line 8 def is_collection @is_collection end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
8 9 10 |
# File 'lib/graphql/association_batch_resolver/association_loader.rb', line 8 def model @model end |
#model_primary_key ⇒ Object (readonly)
Returns the value of attribute model_primary_key.
8 9 10 |
# File 'lib/graphql/association_batch_resolver/association_loader.rb', line 8 def model_primary_key @model_primary_key end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/graphql/association_batch_resolver/association_loader.rb', line 8 def @options end |
#scope ⇒ Object
Returns the value of attribute scope.
10 11 12 |
# File 'lib/graphql/association_batch_resolver/association_loader.rb', line 10 def scope @scope end |
Class Method Details
.validate(model, association_name, options = {}) ⇒ Object
12 13 14 15 |
# File 'lib/graphql/association_batch_resolver/association_loader.rb', line 12 def self.validate(model, association_name, = {}) new(model, association_name, ) nil end |
Instance Method Details
#cache_key(record) ⇒ Object
We want to load the associations on all records, even if they have the same id
36 37 38 |
# File 'lib/graphql/association_batch_resolver/association_loader.rb', line 36 def cache_key(record) record.object_id end |
#load(record) ⇒ Object
29 30 31 32 33 |
# File 'lib/graphql/association_batch_resolver/association_loader.rb', line 29 def load(record) raise TypeError, "#{model} loader can't load association for #{record.class}" unless record.is_a?(model) super end |
#perform(records) ⇒ Object
40 41 42 43 |
# File 'lib/graphql/association_batch_resolver/association_loader.rb', line 40 def perform(records) preload_association(records) records.each { |record| fulfill(record, read_association(record)) } end |