Class: CardDB::Rails::GraphQL::Dataloader::RecordSource

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

Instance Method Summary collapse

Constructor Details

#initialize(dataset_key:, publisher_slug: nil, game_key: nil, client: nil) ⇒ RecordSource

Returns a new instance of RecordSource.



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

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

#fetch(identifiers) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/carddb/rails/graphql/dataloader/record_source.rb', line 16

def fetch(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?

  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
end