Class: CardDB::Rails::GraphQL::DeckLoader

Inherits:
GraphQL::Batch::Loader
  • Object
show all
Defined in:
lib/carddb/rails/graphql/deck_loader.rb

Instance Method Summary collapse

Constructor Details

#initialize(client: nil, read_state: 'DRAFT') ⇒ DeckLoader

Returns a new instance of DeckLoader.



9
10
11
12
13
# File 'lib/carddb/rails/graphql/deck_loader.rb', line 9

def initialize(client: nil, read_state: 'DRAFT')
  super()
  @client = client
  @read_state = read_state
end

Instance Method Details

#perform(ids) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/carddb/rails/graphql/deck_loader.rb', line 15

def perform(ids)
  client = @client || CardDB::Rails.client

  results = client.batch do |batch|
    ids.each do |id|
      batch.decks.get(id, read_state: @read_state)
    end
  end

  ids.each_with_index do |id, index|
    fulfill(id, results[index])
  end
end