Class: SolidusGraphqlApi::BatchLoader::HasManyThrough

Inherits:
SolidusGraphqlApi::BatchLoader show all
Defined in:
lib/solidus_graphql_api/batch_loader/has_many_through.rb

Overview

A batch loader for has_many :through associations.

Constant Summary

Constants inherited from SolidusGraphqlApi::BatchLoader

LOADER_CLASSES

Instance Attribute Summary

Attributes inherited from SolidusGraphqlApi::BatchLoader

#object, #options, #reflection

Instance Method Summary collapse

Methods inherited from SolidusGraphqlApi::BatchLoader

for, #initialize

Constructor Details

This class inherits a constructor from SolidusGraphqlApi::BatchLoader

Instance Method Details

#loadObject



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/solidus_graphql_api/batch_loader/has_many_through.rb', line 7

def load
  graphql_loader_for(object.id, default_value: []) do |object_ids, loader|
    records_by_parent = group_records_by_parent(retrieve_records_for(object_ids))

    records_by_parent.each_pair do |parent_id, children|
      loader.call(parent_id) do |memo|
        memo.concat(children)
      end
    end
  end
end