Commit 5e9bd39f authored by Sean Arnold's avatar Sean Arnold

Add issuable state count type for Project grpahql

- reuse issue resolver fields
- Use IssuablesCountForState
parent 2bef64c0
# frozen_string_literal: true
module Resolvers
module IssueResolverFields
extend ActiveSupport::Concern
prepended do
argument :iid, GraphQL::STRING_TYPE,
required: false,
description: 'IID of the issue. For example, "1"'
argument :iids, [GraphQL::STRING_TYPE],
required: false,
description: 'List of IIDs of issues. For example, [1, 2]'
argument :state, Types::IssuableStateEnum,
required: false,
description: 'Current state of this issue'
argument :label_name, GraphQL::STRING_TYPE.to_list_type,
required: false,
description: 'Labels applied to this issue'
argument :milestone_title, GraphQL::STRING_TYPE.to_list_type,
required: false,
description: 'Milestones applied to this issue'
argument :assignee_username, GraphQL::STRING_TYPE,
required: false,
description: 'Username of a user assigned to the issues'
argument :assignee_id, GraphQL::STRING_TYPE,
required: false,
description: 'ID of a user assigned to the issues, "none" and "any" values supported'
argument :created_before, Types::TimeType,
required: false,
description: 'Issues created before this date'
argument :created_after, Types::TimeType,
required: false,
description: 'Issues created after this date'
argument :updated_before, Types::TimeType,
required: false,
description: 'Issues updated before this date'
argument :updated_after, Types::TimeType,
required: false,
description: 'Issues updated after this date'
argument :closed_before, Types::TimeType,
required: false,
description: 'Issues closed before this date'
argument :closed_after, Types::TimeType,
required: false,
description: 'Issues closed after this date'
argument :search, GraphQL::STRING_TYPE,
required: false,
description: 'Search query for issue title or description'
argument :sort, Types::IssueSortEnum,
description: 'Sort issues by this criteria',
required: false,
default_value: 'created_desc'
argument :types, [Types::IssueTypeEnum],
as: :issue_types,
description: 'Filter issues by the given issue types',
required: false
end
end
end
# frozen_string_literal: true
module Resolvers
class IssueStatusCountsResolver < BaseResolver
prepend Resolvers::IssueResolverFields
type Types::IssueStatusCountsType, null: true
def resolve(**args)
# The project could have been loaded in batch by `BatchLoader`.
# At this point we need the `id` of the project to query for issues, so
# make sure it's loaded and not `nil` before continuing.
parent = object.respond_to?(:sync) ? object.sync : object
return Issue.none if parent.nil?
# Will need to be be made group & namespace aware with
# https://gitlab.com/gitlab-org/gitlab-foss/issues/54520
args[:iids] ||= [args.delete(:iid)].compact if args[:iid]
args[:attempt_project_search_optimizations] = true if args[:search].present?
finder = IssuesFinder.new(current_user, args)
Gitlab::IssuablesCountForState.new(finder, parent)
end
end
end
......@@ -2,57 +2,7 @@
module Resolvers
class IssuesResolver < BaseResolver
argument :iid, GraphQL::STRING_TYPE,
required: false,
description: 'IID of the issue. For example, "1"'
argument :iids, [GraphQL::STRING_TYPE],
required: false,
description: 'List of IIDs of issues. For example, [1, 2]'
argument :state, Types::IssuableStateEnum,
required: false,
description: 'Current state of this issue'
argument :label_name, GraphQL::STRING_TYPE.to_list_type,
required: false,
description: 'Labels applied to this issue'
argument :milestone_title, GraphQL::STRING_TYPE.to_list_type,
required: false,
description: 'Milestones applied to this issue'
argument :assignee_username, GraphQL::STRING_TYPE,
required: false,
description: 'Username of a user assigned to the issues'
argument :assignee_id, GraphQL::STRING_TYPE,
required: false,
description: 'ID of a user assigned to the issues, "none" and "any" values supported'
argument :created_before, Types::TimeType,
required: false,
description: 'Issues created before this date'
argument :created_after, Types::TimeType,
required: false,
description: 'Issues created after this date'
argument :updated_before, Types::TimeType,
required: false,
description: 'Issues updated before this date'
argument :updated_after, Types::TimeType,
required: false,
description: 'Issues updated after this date'
argument :closed_before, Types::TimeType,
required: false,
description: 'Issues closed before this date'
argument :closed_after, Types::TimeType,
required: false,
description: 'Issues closed after this date'
argument :search, GraphQL::STRING_TYPE,
required: false,
description: 'Search query for issue title or description'
argument :sort, Types::IssueSortEnum,
description: 'Sort issues by this criteria',
required: false,
default_value: 'created_desc'
argument :types, [Types::IssueTypeEnum],
as: :issue_types,
description: 'Filter issues by the given issue types',
required: false
prepend Resolvers::IssueResolverFields
type Types::IssueType, null: true
......
# frozen_string_literal: true
module Types
class IssueStatusCountsType < BaseObject
graphql_name 'IssueStatusCountsType'
description "Represents total number of issues for the represented categories"
authorize :read_issue
::Gitlab::IssuablesCountForState::STATES.each do |status|
field status,
GraphQL::INT_TYPE,
null: true,
description: "Number of issues with status #{status.upcase} for the project"
end
end
end
......@@ -148,6 +148,12 @@ module Types
description: 'Issues of the project',
resolver: Resolvers::IssuesResolver
field :issue_status_counts,
Types::IssueStatusCountsType,
null: true,
description: 'Counts of issues by status for the project',
resolver: Resolvers::IssueStatusCountsResolver
field :milestones, Types::MilestoneType.connection_type, null: true,
description: 'Milestones of the project',
resolver: Resolvers::ProjectMilestonesResolver
......@@ -164,8 +170,8 @@ module Types
resolver: Resolvers::EnvironmentsResolver
field :sast_ci_configuration, ::Types::CiConfiguration::Sast::Type, null: true,
description: 'SAST CI configuration for the project',
resolver: ::Resolvers::CiConfiguration::SastResolver
description: 'SAST CI configuration for the project',
resolver: ::Resolvers::CiConfiguration::SastResolver
field :issue,
Types::IssueType,
......
......@@ -9,9 +9,16 @@ module Gitlab
# The state values that can be safely casted to a Symbol.
STATES = %w[opened closed merged all].freeze
attr_reader :project
def self.declarative_policy_class
'IssuablePolicy'
end
# finder - The finder class to use for retrieving the issuables.
def initialize(finder)
def initialize(finder, project = nil)
@finder = finder
@project = project
@cache = Gitlab::SafeRequestStore[CACHE_KEY] ||= initialize_cache
end
......@@ -19,6 +26,11 @@ module Gitlab
self[state || :opened]
end
# Define method for each status
STATES.each do |status|
define_method(status) { self[status] }
end
# Returns the count for the given state.
#
# state - The name of the state as either a String or a Symbol.
......
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