summaryrefslogtreecommitdiff
path: root/app/graphql/resolvers/branch_commit_resolver.rb
blob: ba235251950fc856c94d3d14d281f182c8ac5c38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen_string_literal: true

module Resolvers
  class BranchCommitResolver < BaseResolver
    type Types::CommitType, null: true

    alias_method :branch, :object

    def resolve(**args)
      commit = branch&.dereferenced_target
      return unless commit

      lazy_project = BatchLoader::GraphQL.for(commit.repository.gl_project_path).batch do |paths, loader|
        paths.each { |path| loader.call(path, Project.find_by_full_path(path)) }
      end

      ::Gitlab::Graphql::Lazy.with_value(lazy_project) do |project|
        ::Commit.new(commit, project) if project
      end
    end
  end
end