2018-09-11 15:08:34 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-23 03:55:14 -04:00
|
|
|
module Resolvers
|
2019-01-30 14:00:30 -05:00
|
|
|
class MergeRequestsResolver < BaseResolver
|
2019-06-03 14:15:04 -04:00
|
|
|
argument :iid, GraphQL::STRING_TYPE,
|
2019-02-12 11:31:18 -05:00
|
|
|
required: false,
|
|
|
|
description: 'The IID of the merge request, e.g., "1"'
|
2018-05-23 03:55:14 -04:00
|
|
|
|
2019-06-03 14:15:04 -04:00
|
|
|
argument :iids, [GraphQL::STRING_TYPE],
|
2019-01-30 14:00:30 -05:00
|
|
|
required: false,
|
|
|
|
description: 'The list of IIDs of issues, e.g., [1, 2]'
|
|
|
|
|
2018-06-14 09:06:53 -04:00
|
|
|
type Types::MergeRequestType, null: true
|
|
|
|
|
|
|
|
alias_method :project, :object
|
|
|
|
|
2019-01-30 14:00:30 -05:00
|
|
|
def resolve(**args)
|
2018-05-23 03:55:14 -04:00
|
|
|
return unless project.present?
|
|
|
|
|
2019-02-12 11:31:18 -05:00
|
|
|
args[:iids] ||= [args[:iid]].compact
|
2019-01-30 14:00:30 -05:00
|
|
|
|
2019-02-14 09:57:09 -05:00
|
|
|
args[:iids].map { |iid| batch_load(iid) }
|
2019-01-30 14:00:30 -05:00
|
|
|
.select(&:itself) # .compact doesn't work on BatchLoader
|
|
|
|
end
|
|
|
|
|
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
|
|
|
def batch_load(iid)
|
2018-11-23 06:26:17 -05:00
|
|
|
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-05-23 03:55:14 -04:00
|
|
|
end
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-05-23 03:55:14 -04:00
|
|
|
end
|
|
|
|
end
|