Class: CardDB::Rails::GraphQL::RecordLoader
- Inherits:
-
GraphQL::Batch::Loader
- Object
- GraphQL::Batch::Loader
- CardDB::Rails::GraphQL::RecordLoader
- Defined in:
- lib/carddb/rails/graphql/record_loader.rb
Instance Method Summary collapse
-
#initialize(dataset_key:, publisher_slug: nil, game_key: nil, client: nil) ⇒ RecordLoader
constructor
A new instance of RecordLoader.
- #perform(identifiers) ⇒ Object
Constructor Details
#initialize(dataset_key:, publisher_slug: nil, game_key: nil, client: nil) ⇒ RecordLoader
Returns a new instance of RecordLoader.
9 10 11 12 13 14 15 |
# File 'lib/carddb/rails/graphql/record_loader.rb', line 9 def initialize(dataset_key:, publisher_slug: nil, game_key: nil, client: nil) super() @dataset_key = dataset_key @publisher_slug = publisher_slug @game_key = game_key @client = client end |
Instance Method Details
#perform(identifiers) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/carddb/rails/graphql/record_loader.rb', line 17 def perform(identifiers) client = @client || CardDB::Rails.client publisher_slug = client.config.resolve_publisher(@publisher_slug) game_key = client.config.resolve_game(@game_key) raise ArgumentError, 'publisher_slug is required (no default configured)' if publisher_slug.nil? || publisher_slug.empty? raise ArgumentError, 'game_key is required (no default configured)' if game_key.nil? || game_key.empty? results = client.batch do |batch| identifiers.each do |identifier| batch.records.get( publisher_slug: publisher_slug, game_key: game_key, dataset_key: @dataset_key, identifier: identifier ) end end identifiers.each_with_index do |identifier, index| fulfill(identifier, results[index]) end end |