2020-05-05 05:09:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Resolvers
|
|
|
|
class BranchCommitResolver < BaseResolver
|
|
|
|
type Types::CommitType, null: true
|
|
|
|
|
|
|
|
alias_method :branch, :object
|
|
|
|
|
|
|
|
def resolve(**args)
|
2021-03-12 16:09:12 -05:00
|
|
|
commit = branch&.dereferenced_target
|
|
|
|
return unless commit
|
2020-05-05 05:09:37 -04:00
|
|
|
|
2021-03-12 16:09:12 -05:00
|
|
|
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
|
2020-05-05 05:09:37 -04:00
|
|
|
|
2021-03-12 16:09:12 -05:00
|
|
|
::Gitlab::Graphql::Lazy.with_value(lazy_project) do |project|
|
|
|
|
::Commit.new(commit, project) if project
|
|
|
|
end
|
2020-05-05 05:09:37 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|