2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-01-28 13:53:01 +01:00
|
|
|
# references:
|
|
|
|
# https://github.com/Shopify/graphql-batch/blob/master/examples/record_loader.rb
|
|
|
|
|
|
|
|
module Loaders
|
|
|
|
class Champ < GraphQL::Batch::Loader
|
|
|
|
def initialize(dossier, private: false)
|
|
|
|
@where = { dossier: dossier, private: private }
|
|
|
|
end
|
|
|
|
|
|
|
|
def load(key)
|
|
|
|
super(key.to_i)
|
|
|
|
end
|
|
|
|
|
|
|
|
def perform(keys)
|
|
|
|
query(keys).each { |record| fulfill(record.stable_id, [record].compact) }
|
2023-04-18 09:31:17 +02:00
|
|
|
keys.each { |key| fulfill(key, []) unless fulfilled?(key) }
|
2021-01-28 13:53:01 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def query(keys)
|
2024-07-01 15:31:32 +02:00
|
|
|
::Champ.where(@where).where(stable_id: keys)
|
2021-01-28 13:53:01 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|