Commit d1e29c00 authored by Mario Celi's avatar Mario Celi Committed by Michael Kozono

Add workItemTypes field to ProjectType in GraphQL

Adds the ability to list all base types in the system
for any given project. They are all fixed for now, but they
will belong to root namespaces in the future
parent d58a6c69
......@@ -6,8 +6,8 @@ module Resolvers
type Types::WorkItems::TypeType.connection_type, null: true
def resolve
# This will require a finder in the future when groups get their work item types
# All groups use the default types for now
# This will require a finder in the future when groups/projects get their work item types
# All groups/projects use the default types for now
::WorkItems::Type.default.order_by_name_asc
end
end
......
......@@ -406,6 +406,11 @@ module Types
description: 'Labels available on this project.',
resolver: Resolvers::LabelsResolver
field :work_item_types, Types::WorkItems::TypeType.connection_type,
resolver: Resolvers::WorkItems::TypesResolver,
description: 'Work item types available to the project.',
feature_flag: :work_items
def avatar_url
object.avatar_url(only_path: false)
end
......
......@@ -13224,6 +13224,7 @@ Represents vulnerability finding of a security report on the pipeline.
| <a id="projectvulnerabilityscanners"></a>`vulnerabilityScanners` | [`VulnerabilityScannerConnection`](#vulnerabilityscannerconnection) | Vulnerability scanners reported on the project vulnerabilities. (see [Connections](#connections)) |
| <a id="projectweburl"></a>`webUrl` | [`String`](#string) | Web URL of the project. |
| <a id="projectwikienabled"></a>`wikiEnabled` | [`Boolean`](#boolean) | Indicates if Wikis are enabled for the current user. |
| <a id="projectworkitemtypes"></a>`workItemTypes` | [`WorkItemTypeConnection`](#workitemtypeconnection) | Work item types available to the project. Available only when feature flag `work_items` is enabled. This flag is disabled by default, because the feature is experimental and is subject to change without notice. (see [Connections](#connections)) |
#### Fields with arguments
......@@ -22,7 +22,7 @@ RSpec.describe GitlabSchema.types['Group'] do
dependency_proxy_blobs dependency_proxy_image_count
dependency_proxy_blob_count dependency_proxy_total_size
dependency_proxy_image_prefix dependency_proxy_image_ttl_policy
shared_runners_setting timelogs organizations contacts
shared_runners_setting timelogs organizations contacts work_item_types
]
expect(described_class).to include_graphql_fields(*expected_fields)
......
......@@ -34,7 +34,7 @@ RSpec.describe GitlabSchema.types['Project'] do
container_repositories container_repositories_count
pipeline_analytics squash_read_only sast_ci_configuration
cluster_agent cluster_agents agent_configurations
ci_template timelogs merge_commit_template squash_commit_template
ci_template timelogs merge_commit_template squash_commit_template work_item_types
]
expect(described_class).to include_graphql_fields(*expected_fields)
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'getting a list of work item types for a project' do
include GraphqlHelpers
let_it_be(:developer) { create(:user) }
let_it_be(:project) { create(:project) }
before_all do
project.add_developer(developer)
end
let(:current_user) { developer }
let(:fields) do
<<~GRAPHQL
workItemTypes{
nodes { id name iconName }
}
GRAPHQL
end
let(:query) do
graphql_query_for(
'project',
{ 'fullPath' => project.full_path },
fields
)
end
context 'when user has access to the project' do
before do
post_graphql(query, current_user: current_user)
end
it_behaves_like 'a working graphql query'
it 'returns all default work item types' do
expect(graphql_data.dig('project', 'workItemTypes', 'nodes')).to match_array(
WorkItems::Type.default.map do |type|
hash_including('id' => type.to_global_id.to_s, 'name' => type.name, 'iconName' => type.icon_name)
end
)
end
end
context "when user doesn't have access to the project" do
let(:current_user) { create(:user) }
before do
post_graphql(query, current_user: current_user)
end
it 'does not return the project' do
expect(graphql_data).to eq('project' => nil)
end
end
context 'when the work_items feature flag is disabled' do
before do
stub_feature_flags(work_items: false)
post_graphql(query, current_user: current_user)
end
it 'makes the workItemTypes field unavailable' do
expect(graphql_errors).to contain_exactly(hash_including("message" => "Field 'workItemTypes' doesn't exist on type 'Project'"))
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