summaryrefslogtreecommitdiff
path: root/app/graphql/loaders/full_path_loader.rb
blob: f99b487ce5d70e8cf3295472c2ccb867bcf56914 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Loaders::FullPathLoader < Loaders::BaseLoader
  class << self
    def project(obj, args, ctx)
      project_by_full_path(args[:full_path])
    end

    def project_by_full_path(full_path)
      self.for(Project).load(full_path)
    end
  end

  attr_reader :model

  def initialize(model)
    @model = model
  end

  def perform(keys)
    # `with_route` prevents relation.all.map(&:full_path)` from being N+1
    relation = model.where_full_path_in(keys).with_route
    fulfill_all(relation, keys, &:full_path)
  end
end