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:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-08 00:07:50 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-08 00:07:50 +0300
commitd203316c80aa27cf747aa29df9f7c2d374965b5f (patch)
treeaab5cde76fbf19a2639f6f9f3cb4f2acdc95f803 /lib/gitlab/graphql
parent8dafc3b65aeb8f50fdfc38fb98d96c3db9e2f607 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/graphql')
-rw-r--r--lib/gitlab/graphql/connections.rb4
-rw-r--r--lib/gitlab/graphql/connections/externally_paginated_array_connection.rb35
-rw-r--r--lib/gitlab/graphql/externally_paginated_array.rb15
3 files changed, 54 insertions, 0 deletions
diff --git a/lib/gitlab/graphql/connections.rb b/lib/gitlab/graphql/connections.rb
index 38c7d98f37c..08d5cd0b72e 100644
--- a/lib/gitlab/graphql/connections.rb
+++ b/lib/gitlab/graphql/connections.rb
@@ -12,6 +12,10 @@ module Gitlab
Gitlab::Graphql::FilterableArray,
Gitlab::Graphql::Connections::FilterableArrayConnection
)
+ GraphQL::Relay::BaseConnection.register_connection_implementation(
+ Gitlab::Graphql::ExternallyPaginatedArray,
+ Gitlab::Graphql::Connections::ExternallyPaginatedArrayConnection
+ )
end
end
end
diff --git a/lib/gitlab/graphql/connections/externally_paginated_array_connection.rb b/lib/gitlab/graphql/connections/externally_paginated_array_connection.rb
new file mode 100644
index 00000000000..f0861260691
--- /dev/null
+++ b/lib/gitlab/graphql/connections/externally_paginated_array_connection.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+# Make a customized connection type
+module Gitlab
+ module Graphql
+ module Connections
+ class ExternallyPaginatedArrayConnection < GraphQL::Relay::ArrayConnection
+ # As the pagination happens externally
+ # we just return all the nodes here.
+ def sliced_nodes
+ @nodes
+ end
+
+ def start_cursor
+ nodes.previous_cursor
+ end
+
+ def end_cursor
+ nodes.next_cursor
+ end
+
+ def next_page?
+ end_cursor.present?
+ end
+
+ def previous_page?
+ start_cursor.present?
+ end
+
+ alias_method :has_next_page, :next_page?
+ alias_method :has_previous_page, :previous_page?
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/graphql/externally_paginated_array.rb b/lib/gitlab/graphql/externally_paginated_array.rb
new file mode 100644
index 00000000000..4797fe15cd3
--- /dev/null
+++ b/lib/gitlab/graphql/externally_paginated_array.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Graphql
+ class ExternallyPaginatedArray < Array
+ attr_reader :previous_cursor, :next_cursor
+
+ def initialize(previous_cursor, next_cursor, *args)
+ super(args)
+ @previous_cursor = previous_cursor
+ @next_cursor = next_cursor
+ end
+ end
+ end
+end