Commit a7fde3da authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Filter archived issues / MRs from GraphQL

Adds a non_archived option to group issues / MRs in GraphQL. By default,
archived objects are not included to match the behavior in the REST API
and UI.

Changelog: added
parent fd2ad8c8
......@@ -10,5 +10,12 @@ module GroupIssuableResolver
default_value: false,
description: "Include #{name_of_things} belonging to subgroups"
end
def non_archived(name_of_things)
argument :non_archived, GraphQL::Types::Boolean,
required: false,
default_value: true,
description: "Return #{name_of_things} from non archived projects"
end
end
end
......@@ -6,6 +6,7 @@ module Resolvers
include GroupIssuableResolver
include_subgroups 'issues'
non_archived 'issues'
def ready?(**args)
if args.dig(:not, :release_tag).present?
......
......@@ -9,6 +9,7 @@ module Resolvers
type Types::MergeRequestType.connection_type, null: true
include_subgroups 'merge requests'
non_archived 'merge requests'
accept_assignee
accept_author
......
......@@ -11481,6 +11481,7 @@ four standard [pagination arguments](#connection-pagination-arguments):
| <a id="groupissuesmilestonetitle"></a>`milestoneTitle` | [`[String]`](#string) | Milestone applied to this issue. |
| <a id="groupissuesmilestonewildcardid"></a>`milestoneWildcardId` | [`MilestoneWildcardId`](#milestonewildcardid) | Filter issues by milestone ID wildcard. |
| <a id="groupissuesmyreactionemoji"></a>`myReactionEmoji` | [`String`](#string) | Filter by reaction emoji applied by the current user. Wildcard values "NONE" and "ANY" are supported. |
| <a id="groupissuesnonarchived"></a>`nonArchived` | [`Boolean`](#boolean) | Return issues from non archived projects. |
| <a id="groupissuesnot"></a>`not` | [`NegatedIssueFilterInput`](#negatedissuefilterinput) | Negated arguments. |
| <a id="groupissuessearch"></a>`search` | [`String`](#string) | Search query for title or description. |
| <a id="groupissuessort"></a>`sort` | [`IssueSort`](#issuesort) | Sort issues by this criteria. |
......@@ -11611,6 +11612,7 @@ four standard [pagination arguments](#connection-pagination-arguments):
| <a id="groupmergerequestsmergedafter"></a>`mergedAfter` | [`Time`](#time) | Merge requests merged after this date. |
| <a id="groupmergerequestsmergedbefore"></a>`mergedBefore` | [`Time`](#time) | Merge requests merged before this date. |
| <a id="groupmergerequestsmilestonetitle"></a>`milestoneTitle` | [`String`](#string) | Title of the milestone. |
| <a id="groupmergerequestsnonarchived"></a>`nonArchived` | [`Boolean`](#boolean) | Return merge requests from non archived projects. |
| <a id="groupmergerequestsnot"></a>`not` | [`MergeRequestsResolverNegatedParams`](#mergerequestsresolvernegatedparams) | List of negated arguments. Warning: this argument is experimental and a subject to change in future. |
| <a id="groupmergerequestssort"></a>`sort` | [`MergeRequestSort`](#mergerequestsort) | Sort merge requests by this criteria. |
| <a id="groupmergerequestssourcebranches"></a>`sourceBranches` | [`[String!]`](#string) | Array of source branch names. All resolved merge requests will have one of these branches as their source. |
......@@ -44,6 +44,31 @@ RSpec.describe 'getting an issue list for a group' do
end
end
context 'when there are archived projects' do
let_it_be(:archived_project) { create(:project, :archived, group: group1) }
let_it_be(:archived_issue) { create(:issue, project: archived_project) }
before_all do
group1.add_developer(current_user)
end
it 'excludes issues from archived projects by default' do
post_graphql(query, current_user: current_user)
expect(issues_ids).to contain_exactly(issue1_gid, issue2_gid)
end
context 'when non_archived is false' do
let(:issue_filter_params) { { non_archived: false } }
it 'includes issues from archived projects' do
post_graphql(query, current_user: current_user)
expect(issues_ids).to contain_exactly(issue1_gid, issue2_gid, archived_issue.to_global_id.to_s)
end
end
end
context 'when there is a confidential issue' do
let_it_be(:confidential_issue1) { create(:issue, :confidential, project: project1) }
let_it_be(:confidential_issue2) { create(:issue, :confidential, project: project2) }
......
......@@ -16,6 +16,9 @@ RSpec.describe 'Query.group.mergeRequests' do
let_it_be(:project_x) { create(:project, :repository) }
let_it_be(:user) { create(:user, developer_projects: [project_x]) }
let_it_be(:archived_project) { create(:project, :archived, :repository, group: group) }
let_it_be(:archived_mr) { create(:merge_request, source_project: archived_project) }
let_it_be(:mr_attrs) do
{ target_branch: 'master' }
end
......@@ -119,4 +122,22 @@ RSpec.describe 'Query.group.mergeRequests' do
expect(mrs_data).to match_array(expected_mrs(mrs_a + mrs_b + mrs_c))
end
end
describe 'passing non_archived: false' do
let(:query) do
<<~GQL
query($path: ID!) {
group(fullPath: $path) {
mergeRequests(nonArchived: false) { nodes { id } }
}
}
GQL
end
it 'can find all merge requests in the group, including from archived projects' do
post_graphql(query, current_user: user, variables: { path: group.full_path })
expect(mrs_data).to match_array(expected_mrs(mrs_a + mrs_b + [archived_mr]))
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment