Commit 30918929 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Implement singular iid for IssuesResolver and ProjectType

parent 564b86a3
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
module Resolvers module Resolvers
class IssuesResolver < BaseResolver class IssuesResolver < BaseResolver
extend ActiveSupport::Concern argument :iid, GraphQL::ID_TYPE,
required: false,
description: 'The IID of the issue, e.g., "1"'
argument :iids, [GraphQL::ID_TYPE], argument :iids, [GraphQL::ID_TYPE],
required: false, required: false,
...@@ -22,6 +24,7 @@ module Resolvers ...@@ -22,6 +24,7 @@ module Resolvers
# Will need to be be made group & namespace aware with # Will need to be be made group & namespace aware with
# https://gitlab.com/gitlab-org/gitlab-ce/issues/54520 # https://gitlab.com/gitlab-org/gitlab-ce/issues/54520
args[:project_id] = project.id args[:project_id] = project.id
args[:iids] ||= [args[:iid]].compact
IssuesFinder.new(context[:current_user], args).execute IssuesFinder.new(context[:current_user], args).execute
end end
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
module Resolvers module Resolvers
class MergeRequestsResolver < BaseResolver class MergeRequestsResolver < BaseResolver
argument :iid, GraphQL::ID_TYPE, argument :iid, GraphQL::ID_TYPE,
required: false, required: false,
description: 'The IID of the merge request, e.g., "1"' description: 'The IID of the merge request, e.g., "1"'
argument :iids, [GraphQL::ID_TYPE], argument :iids, [GraphQL::ID_TYPE],
required: false, required: false,
...@@ -17,7 +17,7 @@ module Resolvers ...@@ -17,7 +17,7 @@ module Resolvers
def resolve(**args) def resolve(**args)
return unless project.present? return unless project.present?
args[:iids] ||= [args[:iid]] args[:iids] ||= [args[:iid]].compact
args[:iids].map(&method(:batch_load)) args[:iids].map(&method(:batch_load))
.select(&:itself) # .compact doesn't work on BatchLoader .select(&:itself) # .compact doesn't work on BatchLoader
......
...@@ -85,6 +85,11 @@ module Types ...@@ -85,6 +85,11 @@ module Types
null: true, null: true,
resolver: Resolvers::IssuesResolver resolver: Resolvers::IssuesResolver
field :issue,
Types::IssueType,
null: true,
resolver: Resolvers::IssuesResolver.single
field :pipelines, field :pipelines,
Types::Ci::PipelineType.connection_type, Types::Ci::PipelineType.connection_type,
null: false, null: false,
......
...@@ -33,6 +33,10 @@ describe Resolvers::IssuesResolver do ...@@ -33,6 +33,10 @@ describe Resolvers::IssuesResolver do
expect(resolve_issues).to contain_exactly(issue, issue2) expect(resolve_issues).to contain_exactly(issue, issue2)
end end
it 'finds a specific issue with iid' do
expect(resolve_issues(iid: issue.iid)).to contain_exactly(issue)
end
it 'finds a specific issue with iids' do it 'finds a specific issue with iids' do
expect(resolve_issues(iids: issue.iid)).to contain_exactly(issue) expect(resolve_issues(iids: issue.iid)).to contain_exactly(issue)
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