Commit 7de56dcd authored by Etienne Baqué's avatar Etienne Baqué

Merge branch 'bw-iteration-globalid' into 'master'

Allow iteration ids to be passed as a Global ID

See merge request gitlab-org/gitlab!57620
parents fd225d48 2cb6f242
---
title: Allow a Global ID to be used when filtering issue by iterationId in GraphQL
merge_request: 57620
author:
type: changed
......@@ -9,7 +9,7 @@ module EE
prepended do
argument :iteration_id, [::GraphQL::ID_TYPE, null: true],
required: false,
description: 'Iterations applied to the issue.'
description: 'List of iteration Global IDs applied to the issue.'
argument :epic_id, GraphQL::STRING_TYPE,
required: false,
description: 'ID of an epic associated with the issues, "none" and "any" values are supported.'
......@@ -18,8 +18,25 @@ module EE
description: 'Weight applied to the issue, "none" and "any" values are supported.'
end
override :resolve_with_lookahead
def resolve_with_lookahead(**args)
args[:iteration_id] = iteration_ids_from_args(args) if args[:iteration_id].present?
super
end
private
# Originally accepted a raw model id. Now accept a gid, but allow a raw id
# for backward compatibility
def iteration_ids_from_args(args)
args[:iteration_id].map do |id|
::GitlabSchema.parse_gid(id, expected_type: ::Iteration).model_id
rescue ::Gitlab::Graphql::Errors::ArgumentError
id
end
end
override :preloads
def preloads
super.merge(
......
......@@ -67,8 +67,28 @@ RSpec.describe Resolvers::IssuesResolver do
end
describe 'filtering by iteration' do
it 'returns issues with iteration' do
expect(resolve_issues(iteration_id: [iteration1.id.to_s])).to contain_exactly(issue1)
let_it_be(:iteration1) { create(:iteration, group: group, start_date: 4.weeks.ago, due_date: 3.weeks.ago) }
let_it_be(:iteration2) { create(:iteration, group: group, start_date: 6.weeks.ago, due_date: 5.weeks.ago) }
let_it_be(:issue_with_iteration1) { create(:issue, project: project, iteration: iteration1) }
let_it_be(:issue_with_iteration2) { create(:issue, project: project, iteration: iteration2) }
let_it_be(:issue_without_iteration) { create(:issue, project: project) }
it 'returns issues with iteration using raw id' do
expect(resolve_issues(iteration_id: [iteration1.id])).to contain_exactly(issue_with_iteration1)
end
it 'returns issues with iteration using global id' do
expect(resolve_issues(iteration_id: [iteration1.to_global_id])).to contain_exactly(issue_with_iteration1)
end
it 'returns issues with list iterations using global id' do
expect(resolve_issues(iteration_id: [iteration1.to_global_id, iteration2.to_global_id]))
.to contain_exactly(issue_with_iteration1, issue_with_iteration2)
end
it 'returns issues with list iterations using a mix' do
expect(resolve_issues(iteration_id: [iteration1.id, iteration2.to_global_id]))
.to contain_exactly(issue_with_iteration1, issue_with_iteration2)
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