Class: CardDB::Rails::GraphQL::Dataloader::GameSource

Inherits:
GraphQL::Dataloader::Source
  • Object
show all
Defined in:
lib/carddb/rails/graphql/dataloader/game_source.rb

Instance Method Summary collapse

Constructor Details

#initialize(publisher_slug: nil, client: nil) ⇒ GameSource

Returns a new instance of GameSource.



8
9
10
11
12
# File 'lib/carddb/rails/graphql/dataloader/game_source.rb', line 8

def initialize(publisher_slug: nil, client: nil)
  super()
  @publisher_slug = publisher_slug
  @client = client
end

Instance Method Details

#fetch(game_keys) ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/carddb/rails/graphql/dataloader/game_source.rb', line 14

def fetch(game_keys)
  client = @client || CardDB::Rails.client
  publisher_slug = client.config.resolve_publisher(@publisher_slug)

  raise ArgumentError, 'publisher_slug is required (no default configured)' if publisher_slug.nil? || publisher_slug.empty?

  client.batch do |batch|
    game_keys.each do |game_key|
      batch.games.get(publisher_slug: publisher_slug, game_key: game_key)
    end
  end
end