Class: Gitlab::Database::Aggregation::Graphql::AggregationConnection

Inherits:
GraphQL::Pagination::Connection
  • Object
show all
Defined in:
lib/gitlab/database/aggregation/graphql/aggregation_connection.rb

Instance Method Summary collapse

Instance Method Details

#cursor_for(node) ⇒ Object

rubocop: enable Naming/PredicateName

Raises:

  • (GraphQL::ExecutionError)


19
20
21
22
23
24
25
26
27
28
# File 'lib/gitlab/database/aggregation/graphql/aggregation_connection.rb', line 19

def cursor_for(node)
  load_nodes
  # The cursor is the absolute index: Base Offset + Index in current batch
  # We use object identity (index) to find the node in the current batch.
  batch_index = nodes.index(node)

  raise GraphQL::ExecutionError, "Node not found in current batch" unless batch_index

  encode((selection_range.first + batch_index).to_s)
end

#has_next_pageObject

rubocop: disable Naming/PredicateName – these methods are part of the GraphQL pagination API



9
10
11
12
# File 'lib/gitlab/database/aggregation/graphql/aggregation_connection.rb', line 9

def has_next_page
  load_nodes
  @has_next_page
end

#has_previous_pageObject



14
15
16
# File 'lib/gitlab/database/aggregation/graphql/aggregation_connection.rb', line 14

def has_previous_page
  selection_range.first > 0
end

#nodesObject



30
31
32
# File 'lib/gitlab/database/aggregation/graphql/aggregation_connection.rb', line 30

def nodes
  load_nodes
end