debian-mirror-gitlab/lib/gitlab/graphql/pagination/externally_paginated_array_connection.rb

44 lines
971 B
Ruby
Raw Normal View History

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
2020-03-13 15:44:24 +05:30
def start_cursor
2020-04-22 19:07:51 +05:30
items.previous_cursor
2020-03-13 15:44:24 +05:30
end
def end_cursor
2020-04-22 19:07:51 +05:30
items.next_cursor
2020-03-13 15:44:24 +05:30
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?
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