2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
module Resolvers
|
2019-07-07 11:18:12 +05:30
|
|
|
class MergeRequestsResolver < BaseResolver
|
2018-11-08 19:23:39 +05:30
|
|
|
argument :iid, GraphQL::ID_TYPE,
|
2019-07-07 11:18:12 +05:30
|
|
|
required: false,
|
|
|
|
description: 'The IID of the merge request, e.g., "1"'
|
|
|
|
|
|
|
|
argument :iids, [GraphQL::ID_TYPE],
|
|
|
|
required: false,
|
|
|
|
description: 'The list of IIDs of issues, e.g., [1, 2]'
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
type Types::MergeRequestType, null: true
|
|
|
|
|
|
|
|
alias_method :project, :object
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
def resolve(**args)
|
2018-11-08 19:23:39 +05:30
|
|
|
return unless project.present?
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
args[:iids] ||= [args[:iid]].compact
|
|
|
|
|
|
|
|
args[:iids].map { |iid| batch_load(iid) }
|
|
|
|
.select(&:itself) # .compact doesn't work on BatchLoader
|
|
|
|
end
|
|
|
|
|
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
|
|
|
def batch_load(iid)
|
2019-02-15 15:39:39 +05:30
|
|
|
BatchLoader.for(iid.to_s).batch(key: project) do |iids, loader, args|
|
|
|
|
args[:key].merge_requests.where(iid: iids).each do |mr|
|
|
|
|
loader.call(mr.iid.to_s, mr)
|
|
|
|
end
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
end
|