2020-08-28 02:10:45 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Resolvers
|
|
|
|
class ProjectMergeRequestsResolver < MergeRequestsResolver
|
2020-11-17 07:09:15 -05:00
|
|
|
type ::Types::MergeRequestType.connection_type, null: true
|
2020-10-05 14:08:51 -04:00
|
|
|
accept_assignee
|
|
|
|
accept_author
|
2020-12-10 07:09:43 -05:00
|
|
|
accept_reviewer
|
2021-01-27 04:09:01 -05:00
|
|
|
|
|
|
|
def resolve(**args)
|
|
|
|
scope = super
|
|
|
|
|
2021-03-04 07:11:11 -05:00
|
|
|
if only_count_is_selected_with_merged_at_filter?(args)
|
2021-01-27 04:09:01 -05:00
|
|
|
MergeRequest::MetricsFinder
|
|
|
|
.new(current_user, args.merge(target_project: project))
|
|
|
|
.execute
|
|
|
|
else
|
|
|
|
scope
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def only_count_is_selected_with_merged_at_filter?(args)
|
|
|
|
return unless lookahead
|
|
|
|
|
2021-02-05 07:09:31 -05:00
|
|
|
argument_names = args.compact.except(:lookahead, :sort, :merged_before, :merged_after).keys
|
2021-01-27 04:09:01 -05:00
|
|
|
|
|
|
|
# no extra filtering arguments are provided
|
|
|
|
return unless argument_names.empty?
|
|
|
|
return unless args[:merged_after] || args[:merged_before]
|
|
|
|
|
|
|
|
# Detecting a specific query pattern:
|
|
|
|
# mergeRequests(mergedAfter: "X", mergedBefore: "Y") {
|
|
|
|
# count
|
|
|
|
# totalTimeToMerge
|
|
|
|
# }
|
|
|
|
allowed_selected_fields = [:count, :total_time_to_merge]
|
2021-02-05 07:09:31 -05:00
|
|
|
selected_fields = lookahead.selections.map(&:field).map(&:original_name) - [:__typename] # ignore __typename meta field
|
2021-01-27 04:09:01 -05:00
|
|
|
|
|
|
|
# only the allowed_selected_fields are present
|
|
|
|
(selected_fields - allowed_selected_fields).empty?
|
|
|
|
end
|
2020-08-28 02:10:45 -04:00
|
|
|
end
|
|
|
|
end
|