Commit c0749f85 authored by charlieablett's avatar charlieablett

Add feature flag

Without the feature flag, the DescendantCountService
functionality is used instead
parent cb5eb4d2
......@@ -28,7 +28,7 @@ class GitlabSchema < GraphQL::Schema
default_max_page_size 100
lazy_resolve Epics::LazyEpicAggregate, :epic_aggregate
lazy_resolve ::Epics::LazyEpicAggregate, :epic_aggregate
class << self
def multiplex(queries, **kwargs)
......
......@@ -74,6 +74,8 @@ class Issue < ApplicationRecord
scope :public_only, -> { where(confidential: false) }
scope :confidential_only, -> { where(confidential: true) }
scope :counts_by_state, -> { reorder(nil).group(:state_id).count }
ignore_column :state, remove_with: '12.7', remove_after: '2019-12-22'
after_commit :expire_etag_cache, unless: :importing?
......
......@@ -102,6 +102,8 @@ module EE
scope :start_date_inherited, -> { where(start_date_is_fixed: [nil, false]) }
scope :due_date_inherited, -> { where(due_date_is_fixed: [nil, false]) }
scope :counts_by_state, -> { group(:state_id).count }
MAX_HIERARCHY_DEPTH = 5
def etag_caching_enabled?
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
describe 'Epic aggregates (count and weight)' do
describe 'Query epic aggregates (count and weight)' do
include GraphqlHelpers
let_it_be(:current_user) { create(:user) }
......@@ -25,18 +25,18 @@ describe 'Epic aggregates (count and weight)' do
let(:epic_aggregates_query) do
<<~QUERY
nodes {
descendantWeightSum {
openedIssues
closedIssues
}
descendantCounts {
openedEpics
closedEpics
openedIssues
closedIssues
}
nodes {
descendantWeightSum {
openedIssues
closedIssues
}
descendantCounts {
openedEpics
closedEpics
openedIssues
closedIssues
}
}
QUERY
end
......@@ -54,88 +54,36 @@ describe 'Epic aggregates (count and weight)' do
it_behaves_like 'a working graphql query'
context 'with feature flag enabled' do
before do
stub_feature_flags(unfiltered_epic_aggregates: true)
end
it 'returns the epic counts' do
epic_count_result = {
"openedEpics" => 1,
"closedEpics" => 2
}
it 'returns the epic counts' do
epic_count_result = {
"openedEpics" => 1,
"closedEpics" => 2
}
is_expected.to include(
a_hash_including('descendantCounts' => a_hash_including(epic_count_result))
)
end
it 'returns the issue counts' do
issue_count_result = {
"openedIssues" => 1,
"closedIssues" => 1
}
is_expected.to include(
a_hash_including('descendantCounts' => a_hash_including(issue_count_result))
)
end
is_expected.to include(
a_hash_including('descendantCounts' => a_hash_including(epic_count_result))
)
end
it 'returns the weights' do
descendant_weight_result = {
"openedIssues" => 5,
"closedIssues" => 7
}
it 'returns the issue counts' do
issue_count_result = {
"openedIssues" => 1,
"closedIssues" => 1
}
is_expected.to include(
a_hash_including('descendantWeightSum' => a_hash_including(descendant_weight_result))
)
end
is_expected.to include(
a_hash_including('descendantCounts' => a_hash_including(issue_count_result))
)
end
context 'with feature flag disabled' do
before do
stub_feature_flags(unfiltered_epic_aggregates: false)
end
context 'when requesting counts' do
let(:epic_aggregates_query) do
<<~QUERY
nodes {
descendantCounts {
openedEpics
closedEpics
openedIssues
closedIssues
}
}
QUERY
end
it 'uses the DescendantCountService' do
expect(Epics::DescendantCountService).to receive(:new)
post_graphql(query, current_user: current_user)
end
end
context 'when requesting weights' do
let(:epic_aggregates_query) do
<<~QUERY
nodes {
descendantWeightSum {
openedIssues
closedIssues
}
}
QUERY
end
it 'returns an error' do
post_graphql(query, current_user: current_user)
expect_graphql_errors_to_include /Field 'descendantWeightSum' doesn't exist on type 'Epic/
end
end
it 'returns the weights' do
descendant_weight_result = {
"openedIssues" => 5,
"closedIssues" => 7
}
is_expected.to include(
a_hash_including('descendantWeightSum' => a_hash_including(descendant_weight_result))
)
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