diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-08 00:07:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-08 00:07:50 +0300 |
commit | d203316c80aa27cf747aa29df9f7c2d374965b5f (patch) | |
tree | aab5cde76fbf19a2639f6f9f3cb4f2acdc95f803 /lib/gitlab/graphql | |
parent | 8dafc3b65aeb8f50fdfc38fb98d96c3db9e2f607 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/graphql')
-rw-r--r-- | lib/gitlab/graphql/connections.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/graphql/connections/externally_paginated_array_connection.rb | 35 | ||||
-rw-r--r-- | lib/gitlab/graphql/externally_paginated_array.rb | 15 |
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 |