debian-mirror-gitlab/app/graphql/resolvers/merge_requests_resolver.rb

39 lines
1.1 KiB
Ruby
Raw Normal View History

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
2019-09-04 21:01:54 +05:30
argument :iid, GraphQL::STRING_TYPE,
2019-07-07 11:18:12 +05:30
required: false,
description: 'The IID of the merge request, e.g., "1"'
2019-09-04 21:01:54 +05:30
argument :iids, [GraphQL::STRING_TYPE],
2019-07-07 11:18:12 +05:30
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-12-04 20:38:33 +05:30
BatchLoader::GraphQL.for(iid.to_s).batch(key: project) do |iids, loader, args|
arg_key = args[:key].respond_to?(:sync) ? args[:key].sync : args[:key]
arg_key.merge_requests.where(iid: iids).each do |mr|
2019-02-15 15:39:39 +05:30
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