Commit cee9aab9 authored by Brett Walker's avatar Brett Walker

Allow iteration ids to be passes as a Global ID

but still support passing raw ids
parent c3468692
---
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 ...@@ -9,7 +9,7 @@ module EE
prepended do prepended do
argument :iteration_id, [::GraphQL::ID_TYPE, null: true], argument :iteration_id, [::GraphQL::ID_TYPE, null: true],
required: false, required: false,
description: 'Iterations applied to the issue.' description: 'List of iteration Global IDs applied to the issue.'
argument :epic_id, GraphQL::STRING_TYPE, argument :epic_id, GraphQL::STRING_TYPE,
required: false, required: false,
description: 'ID of an epic associated with the issues, "none" and "any" values are supported.' description: 'ID of an epic associated with the issues, "none" and "any" values are supported.'
...@@ -18,8 +18,25 @@ module EE ...@@ -18,8 +18,25 @@ module EE
description: 'Weight applied to the issue, "none" and "any" values are supported.' description: 'Weight applied to the issue, "none" and "any" values are supported.'
end 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 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 override :preloads
def preloads def preloads
super.merge( super.merge(
......
...@@ -67,8 +67,23 @@ RSpec.describe Resolvers::IssuesResolver do ...@@ -67,8 +67,23 @@ RSpec.describe Resolvers::IssuesResolver do
end end
describe 'filtering by iteration' do describe 'filtering by iteration' do
it 'returns issues with iteration' do let_it_be(:iteration1) { create(:iteration, group: group) }
expect(resolve_issues(iteration_id: [iteration1.id.to_s])).to contain_exactly(issue1) let_it_be(:iteration2) { create(:iteration, group: group) }
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 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