diff --git a/app/graphql/loaders/champ.rb b/app/graphql/loaders/champ.rb deleted file mode 100644 index 61f270352ce..00000000000 --- a/app/graphql/loaders/champ.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -# 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) } - keys.each { |key| fulfill(key, []) unless fulfilled?(key) } - end - - private - - def query(keys) - ::Champ.where(@where).where(stable_id: keys) - end - end -end diff --git a/app/graphql/types/dossier_type.rb b/app/graphql/types/dossier_type.rb index 4a90b7cee62..a3b2fb1e71c 100644 --- a/app/graphql/types/dossier_type.rb +++ b/app/graphql/types/dossier_type.rb @@ -162,9 +162,7 @@ def avis(id: nil) def champs(id: nil) if id.present? - Loaders::Champ - .for(object, private: false) - .load(ApplicationRecord.id_from_typed_id(id)) + object.project_champs_public.filter { _1.stable_id.to_s == ApplicationRecord.id_from_typed_id(id).to_s } else object.project_champs_public.filter(&:visible?) end @@ -172,9 +170,7 @@ def champs(id: nil) def annotations(id: nil) if id.present? - Loaders::Champ - .for(object, private: true) - .load(ApplicationRecord.id_from_typed_id(id)) + object.project_champs_private.filter { _1.stable_id.to_s == ApplicationRecord.id_from_typed_id(id).to_s } else object.project_champs_private.filter(&:visible?) end