class Types::SubcategoryType < Types::BaseObject
def records
BatchLoader.for(object.category_id).batch do |category_ids, loader|
records = Record.where(category_id: category_ids).group_by(&:subcategory_id)
loader.call(object.subcategory_id, records[object.id])
end
end
end
The goal is to load all records across all subcategories of a category at once. Currently the example above will return null because the batch call uses the category_id as the key, but on the loader call I'm using a subcategory_id.
Is something like this possible?
The goal is to load all
records
across allsubcategories
of acategory
at once. Currently the example above will returnnull
because thebatch
call uses thecategory_id
as the key, but on theloader
call I'm using asubcategory_id
.