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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.6 KiB
Ruby
Raw Permalink 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
2023-05-27 22:25:52 +05:30
# Filter out all elements with blank values. If any of the values are not
# scalars, e.g. hashes or array, filter blank values from them and remove
# them if the resulting collection is empty.
argument_names = args.except(:lookahead, :sort, :merged_before, :merged_after).filter_map do |key, value|
value = value.to_hash.compact if value.respond_to?(:to_hash)
key if value.present?
end
2021-03-11 19:13:27 +05:30
# 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