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)
|
|
|
|
::Champ.where(@where)
|
|
|
|
.includes(:type_de_champ)
|
|
|
|
.where(types_de_champ: { stable_id: keys })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|