Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/graphql/pagination/keyset')
-rw-r--r--lib/gitlab/graphql/pagination/keyset/connection.rb4
-rw-r--r--lib/gitlab/graphql/pagination/keyset/generic_keyset_pagination.rb13
-rw-r--r--lib/gitlab/graphql/pagination/keyset/order_info.rb10
-rw-r--r--lib/gitlab/graphql/pagination/keyset/query_builder.rb4
4 files changed, 22 insertions, 9 deletions
diff --git a/lib/gitlab/graphql/pagination/keyset/connection.rb b/lib/gitlab/graphql/pagination/keyset/connection.rb
index e525996ec10..61903c566f0 100644
--- a/lib/gitlab/graphql/pagination/keyset/connection.rb
+++ b/lib/gitlab/graphql/pagination/keyset/connection.rb
@@ -114,7 +114,7 @@ module Gitlab
def limited_nodes
strong_memoize(:limited_nodes) do
if first && last
- raise Gitlab::Graphql::Errors::ArgumentError.new("Can only provide either `first` or `last`, not both")
+ raise Gitlab::Graphql::Errors::ArgumentError, "Can only provide either `first` or `last`, not both"
end
if last
@@ -158,7 +158,7 @@ module Gitlab
def ordered_items
strong_memoize(:ordered_items) do
unless items.primary_key.present?
- raise ArgumentError.new('Relation must have a primary key')
+ raise ArgumentError, 'Relation must have a primary key'
end
list = OrderInfo.build_order_list(items)
diff --git a/lib/gitlab/graphql/pagination/keyset/generic_keyset_pagination.rb b/lib/gitlab/graphql/pagination/keyset/generic_keyset_pagination.rb
index 318c6e1734f..f1b74999897 100644
--- a/lib/gitlab/graphql/pagination/keyset/generic_keyset_pagination.rb
+++ b/lib/gitlab/graphql/pagination/keyset/generic_keyset_pagination.rb
@@ -10,6 +10,8 @@ module Gitlab
extend ActiveSupport::Concern
def ordered_items
+ raise ArgumentError, 'Relation must have a primary key' unless items.primary_key.present?
+
return super unless Gitlab::Pagination::Keyset::Order.keyset_aware?(items)
items
@@ -40,6 +42,17 @@ module Gitlab
sliced = slice_nodes(sliced, after, :after) if after.present?
sliced
end
+
+ def items
+ original_items = super
+ return original_items if Gitlab::Pagination::Keyset::Order.keyset_aware?(original_items) || Feature.disabled?(:new_graphql_keyset_pagination)
+
+ strong_memoize(:generic_keyset_pagination_items) do
+ rebuilt_items_with_keyset_order, success = Gitlab::Pagination::Keyset::SimpleOrderBuilder.build(original_items)
+
+ success ? rebuilt_items_with_keyset_order : original_items
+ end
+ end
end
end
end
diff --git a/lib/gitlab/graphql/pagination/keyset/order_info.rb b/lib/gitlab/graphql/pagination/keyset/order_info.rb
index 0494329bfd9..57e85ebe7f6 100644
--- a/lib/gitlab/graphql/pagination/keyset/order_info.rb
+++ b/lib/gitlab/graphql/pagination/keyset/order_info.rb
@@ -36,24 +36,24 @@ module Gitlab
def self.validate_ordering(relation, order_list)
if order_list.empty?
- raise ArgumentError.new('A minimum of 1 ordering field is required')
+ raise ArgumentError, 'A minimum of 1 ordering field is required'
end
if order_list.count > 2
# Keep in mind an order clause for primary key is added if one is not present
# lib/gitlab/graphql/pagination/keyset/connection.rb:97
- raise ArgumentError.new('A maximum of 2 ordering fields are allowed')
+ raise ArgumentError, 'A maximum of 2 ordering fields are allowed'
end
# make sure the last ordering field is non-nullable
attribute_name = order_list.last&.attribute_name
if relation.columns_hash[attribute_name].null
- raise ArgumentError.new("Column `#{attribute_name}` must not allow NULL")
+ raise ArgumentError, "Column `#{attribute_name}` must not allow NULL"
end
if order_list.last.attribute_name != relation.primary_key
- raise ArgumentError.new("Last ordering field must be the primary key, `#{relation.primary_key}`")
+ raise ArgumentError, "Last ordering field must be the primary key, `#{relation.primary_key}`"
end
end
@@ -121,4 +121,4 @@ module Gitlab
end
end
-Gitlab::Graphql::Pagination::Keyset::OrderInfo.prepend_if_ee('EE::Gitlab::Graphql::Pagination::Keyset::OrderInfo')
+Gitlab::Graphql::Pagination::Keyset::OrderInfo.prepend_mod_with('Gitlab::Graphql::Pagination::Keyset::OrderInfo')
diff --git a/lib/gitlab/graphql/pagination/keyset/query_builder.rb b/lib/gitlab/graphql/pagination/keyset/query_builder.rb
index ee9c902c735..a2f53ae83dd 100644
--- a/lib/gitlab/graphql/pagination/keyset/query_builder.rb
+++ b/lib/gitlab/graphql/pagination/keyset/query_builder.rb
@@ -12,7 +12,7 @@ module Gitlab
@before_or_after = before_or_after
if order_list.empty?
- raise ArgumentError.new('No ordering scopes have been supplied')
+ raise ArgumentError, 'No ordering scopes have been supplied'
end
end
@@ -49,7 +49,7 @@ module Gitlab
end
if order_list.count == 1 && attr_values.first.nil?
- raise Gitlab::Graphql::Errors::ArgumentError.new('Before/after cursor invalid: `nil` was provided as only sortable value')
+ raise Gitlab::Graphql::Errors::ArgumentError, 'Before/after cursor invalid: `nil` was provided as only sortable value'
end
if order_list.count == 1 || attr_values.first.present?