Class: GraphQL::Extras::PreloadSource
- Inherits:
-
Dataloader::Source
- Object
- Dataloader::Source
- GraphQL::Extras::PreloadSource
- Defined in:
- lib/graphql/extras/preload.rb
Instance Method Summary collapse
- #fetch(records) ⇒ Object
-
#initialize(preload) ⇒ PreloadSource
constructor
A new instance of PreloadSource.
Constructor Details
#initialize(preload) ⇒ PreloadSource
Returns a new instance of PreloadSource.
4 5 6 |
# File 'lib/graphql/extras/preload.rb', line 4 def initialize(preload) @preload = preload end |
Instance Method Details
#fetch(records) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/graphql/extras/preload.rb', line 8 def fetch(records) if ActiveRecord::VERSION::MAJOR >= 7 preloader = ActiveRecord::Associations::Preloader.new( records: records, associations: @preload ) preloader.call else preloader = ActiveRecord::Associations::Preloader.new preloader.preload(records, @preload) end records end |