Commit 447d8623 authored by David Kim's avatar David Kim

Merge branch 'dz-project-topic-graphql' into 'master'

Add project topic to graphql

See merge request gitlab-org/gitlab!60397
parents 39200f9a 890c6548
......@@ -24,6 +24,10 @@ module Resolvers
required: false,
description: 'Sort order of results.'
argument :topics, type: [GraphQL::STRING_TYPE],
required: false,
description: 'Filters projects by topics.'
def resolve(**args)
ProjectsFinder
.new(current_user: current_user, params: project_finder_params(args), project_ids_relation: parse_gids(args[:ids]))
......@@ -38,7 +42,8 @@ module Resolvers
non_public: params[:membership],
search: params[:search],
search_namespaces: params[:search_namespaces],
sort: params[:sort]
sort: params[:sort],
topic: params[:topics]
}.compact
end
......
......@@ -283,6 +283,7 @@ four standard [pagination arguments](#connection-pagination-arguments):
| <a id="queryprojectssearch"></a>`search` | [`String`](#string) | Search query for project name, path, or description. |
| <a id="queryprojectssearchnamespaces"></a>`searchNamespaces` | [`Boolean`](#boolean) | Include namespace in project search. |
| <a id="queryprojectssort"></a>`sort` | [`String`](#string) | Sort order of results. |
| <a id="queryprojectstopics"></a>`topics` | [`[String!]`](#string) | Filters projects by topics. |
### `Query.runner`
......
......@@ -150,13 +150,33 @@ RSpec.describe ProjectsFinder do
describe 'filter by topics' do
before do
public_project.topic_list = 'foo'
public_project.topic_list = 'foo, bar'
public_project.save!
end
let(:params) { { topic: 'foo' } }
context 'single topic' do
let(:params) { { topic: 'foo' } }
it { is_expected.to eq([public_project]) }
it { is_expected.to eq([public_project]) }
end
context 'multiple topics' do
let(:params) { { topic: 'bar, foo' } }
it { is_expected.to eq([public_project]) }
end
context 'one topic matches, other one does not' do
let(:params) { { topic: 'foo, xyz' } }
it { is_expected.to eq([]) }
end
context 'no matching topic' do
let(:params) { { topic: 'xyz' } }
it { is_expected.to eq([]) }
end
end
describe 'filter by personal' do
......
......@@ -10,7 +10,7 @@ RSpec.describe Resolvers::ProjectsResolver do
let_it_be(:group) { create(:group, name: 'public-group') }
let_it_be(:private_group) { create(:group, name: 'private-group') }
let_it_be(:project) { create(:project, :public) }
let_it_be(:project) { create(:project, :public, tag_list: %w(ruby javascript)) }
let_it_be(:other_project) { create(:project, :public) }
let_it_be(:group_project) { create(:project, :public, group: group) }
let_it_be(:private_project) { create(:project, :private) }
......@@ -70,6 +70,14 @@ RSpec.describe Resolvers::ProjectsResolver do
is_expected.to be_empty
end
end
context 'when topics filter is provided' do
let(:filters) { { topics: %w(ruby) } }
it 'returns matching project' do
is_expected.to contain_exactly(project)
end
end
end
end
......@@ -138,6 +146,14 @@ RSpec.describe Resolvers::ProjectsResolver do
is_expected.to match_array([named_project3, named_project1, named_project2])
end
end
context 'when topics filter is provided' do
let(:filters) { { topics: %w(ruby) } }
it 'returns matching project' do
is_expected.to contain_exactly(project)
end
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