2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Make a customized connection type
|
|
|
|
module Gitlab
|
|
|
|
module Graphql
|
2020-04-22 19:07:51 +05:30
|
|
|
module Pagination
|
|
|
|
class ExternallyPaginatedArrayConnection < GraphQL::Pagination::ArrayConnection
|
2021-02-22 17:27:13 +05:30
|
|
|
include ::Gitlab::Graphql::ConnectionCollectionMethods
|
|
|
|
prepend ::Gitlab::Graphql::ConnectionRedaction
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
delegate :start_cursor, :end_cursor, to: :items
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
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?
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def load_nodes
|
|
|
|
@nodes ||= begin
|
|
|
|
# As the pagination happens externally we just grab all the nodes
|
|
|
|
limited_nodes = items
|
|
|
|
|
|
|
|
limited_nodes = limited_nodes.first(first) if first
|
|
|
|
limited_nodes = limited_nodes.last(last) if last
|
|
|
|
|
|
|
|
limited_nodes
|
|
|
|
end
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|