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

44 lines
1.3 KiB
Ruby
Raw Normal View History

2020-11-24 15:15:51 +05:30
# frozen_string_literal: true
module Resolvers
class ProjectMergeRequestsResolver < MergeRequestsResolver
2021-01-29 00:20:46 +05:30
type ::Types::MergeRequestType.connection_type, null: true
2021-01-03 14:25:43 +05:30
accept_assignee
accept_author
2021-02-22 17:27:13 +05:30
accept_reviewer
2021-03-11 19:13:27 +05:30
def resolve(**args)
scope = super
2021-04-17 20:07:23 +05:30
if only_count_is_selected_with_merged_at_filter?(args)
2021-03-11 19:13:27 +05:30
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
argument_names = args.compact.except(:lookahead, :sort, :merged_before, :merged_after).keys
# 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]
selected_fields = lookahead.selections.map(&:field).map(&:original_name) - [:__typename] # ignore __typename meta field
# only the allowed_selected_fields are present
(selected_fields - allowed_selected_fields).empty?
end
2020-11-24 15:15:51 +05:30
end
end