demarches-normaliennes/app/graphql/connections/dossiers_connection.rb

32 lines
717 B
Ruby
Raw Normal View History

module Connections
class DossiersConnection < CursorConnection
def initialize(items, lookahead: nil, **kwargs)
super(items, **kwargs)
@lookahead = lookahead
end
def load_nodes
if @nodes.nil? && preload?
DossierPreloader.new(super).all
else
super
end
end
private
def order_column
arguments[:updated_since].present? ? :updated_at : :depose_at
end
def order_table
:dossiers
end
# We check if the query selects champs form dossier. If it's the case we preload the dossier.
def preload?
@lookahead.selection(:nodes).selects?(:champs) || @lookahead.selection(:nodes).selects?(:annotations)
end
end
end