Skip to content
代码片段 群组 项目
未验证 提交 145f11da 编辑于 作者: lma-git's avatar lma-git
浏览文件

Add star and forks count to CiCatalogResource GraphQL

Added GraphQL fields star_count and forks_count
to CiCatalogResource type.
上级 7d5b3f3f
No related branches found
No related tags found
无相关合并请求
......@@ -29,9 +29,21 @@ class ResourceType < BaseObject
resolver: Resolvers::ReleasesResolver,
alpha: { milestone: '16.1' }
field :star_count, GraphQL::Types::Int, null: false,
description: 'Number of times the catalog resource has been starred.',
alpha: { milestone: '16.1' }
field :forks_count, GraphQL::Types::Int, null: false, calls_gitaly: true,
description: 'Number of times the catalog resource has been forked.',
alpha: { milestone: '16.1' }
def web_path
::Gitlab::Routing.url_helpers.project_path(object.project)
end
def forks_count
BatchLoader::GraphQL.wrap(object.forks_count)
end
end
# rubocop: enable Graphql/AuthorizeTypes
end
......
......@@ -17,7 +17,7 @@ class Resource < ::ApplicationRecord
scope :order_by_name_desc, -> { joins(:project).merge(Project.sorted_by_name_desc) }
scope :order_by_name_asc, -> { joins(:project).merge(Project.sorted_by_name_asc) }
delegate :avatar_path, :description, :name, to: :project
delegate :avatar_path, :description, :name, :star_count, :forks_count, to: :project
def versions
project.releases.order_released_desc
......
......@@ -12400,9 +12400,11 @@ Represents the total number of issues and their weights for a particular day.
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="cicatalogresourcedescription"></a>`description` **{warning-solid}** | [`String`](#string) | **Introduced** in 15.11. This feature is an Experiment. It can be changed or removed at any time. Description of the catalog resource. |
| <a id="cicatalogresourceforkscount"></a>`forksCount` **{warning-solid}** | [`Int!`](#int) | **Introduced** in 16.1. This feature is an Experiment. It can be changed or removed at any time. Number of times the catalog resource has been forked. |
| <a id="cicatalogresourceicon"></a>`icon` **{warning-solid}** | [`String`](#string) | **Introduced** in 15.11. This feature is an Experiment. It can be changed or removed at any time. Icon for the catalog resource. |
| <a id="cicatalogresourceid"></a>`id` **{warning-solid}** | [`ID!`](#id) | **Introduced** in 15.11. This feature is an Experiment. It can be changed or removed at any time. ID of the catalog resource. |
| <a id="cicatalogresourcename"></a>`name` **{warning-solid}** | [`String`](#string) | **Introduced** in 15.11. This feature is an Experiment. It can be changed or removed at any time. Name of the catalog resource. |
| <a id="cicatalogresourcestarcount"></a>`starCount` **{warning-solid}** | [`Int!`](#int) | **Introduced** in 16.1. This feature is an Experiment. It can be changed or removed at any time. Number of times the catalog resource has been starred. |
| <a id="cicatalogresourcewebpath"></a>`webPath` **{warning-solid}** | [`String`](#string) | **Introduced** in 16.1. This feature is an Experiment. It can be changed or removed at any time. Web path of the catalog resource. |
 
#### Fields with arguments
......@@ -14,7 +14,8 @@
:project, :with_avatar,
name: 'Component Repository',
description: 'A simple component',
namespace: namespace
namespace: namespace,
star_count: 1
)
end
......@@ -67,7 +68,9 @@
a_graphql_entity_for(
resource1, :name, :description,
icon: project1.avatar_path,
webPath: "/#{project1.full_path}"
webPath: "/#{project1.full_path}",
starCount: project1.star_count,
forksCount: project1.forks_count
)
)
end
......
......@@ -13,6 +13,8 @@
icon
web_path
versions
star_count
forks_count
]
expect(described_class).to have_graphql_fields(*expected_fields)
......
......@@ -19,6 +19,8 @@
it { is_expected.to delegate_method(:avatar_path).to(:project) }
it { is_expected.to delegate_method(:description).to(:project) }
it { is_expected.to delegate_method(:name).to(:project) }
it { is_expected.to delegate_method(:star_count).to(:project) }
it { is_expected.to delegate_method(:forks_count).to(:project) }
describe '.for_projects' do
it 'returns catalog resources for the given project IDs' do
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册