Class: HQ::GraphQL::RecordLoader
- Inherits:
-
GraphQL::Batch::Loader
- Object
- GraphQL::Batch::Loader
- HQ::GraphQL::RecordLoader
- Defined in:
- lib/hq/graphql/record_loader.rb
Instance Method Summary collapse
-
#initialize(model, column: model.primary_key, where: nil) ⇒ RecordLoader
constructor
A new instance of RecordLoader.
- #load(key) ⇒ Object
- #perform(keys) ⇒ Object
Constructor Details
#initialize(model, column: model.primary_key, where: nil) ⇒ RecordLoader
6 7 8 9 10 11 12 |
# File 'lib/hq/graphql/record_loader.rb', line 6 def initialize(model, column: model.primary_key, where: nil) super() @model = model @column = column.to_s @column_type = model.type_for_attribute(@column) @where = where end |
Instance Method Details
#load(key) ⇒ Object
14 15 16 |
# File 'lib/hq/graphql/record_loader.rb', line 14 def load(key) super(@column_type.cast(key)) end |
#perform(keys) ⇒ Object
18 19 20 21 |
# File 'lib/hq/graphql/record_loader.rb', line 18 def perform(keys) query(keys).each { |record| fulfill(record.public_send(@column), record) } keys.each { |key| fulfill(key, nil) unless fulfilled?(key) } end |