Class: Gitlab::Graphql::Pagination::ActiveRecordArrayConnection

Inherits:
GraphQL::Pagination::ArrayConnection
  • Object
show all
Includes:
ConnectionCollectionMethods, ConnectionRedaction
Defined in:
lib/gitlab/graphql/pagination/active_record_array_connection.rb

Instance Method Summary collapse

Instance Method Details

#cursor_for(item) ⇒ Object



52
53
54
55
56
# File 'lib/gitlab/graphql/pagination/active_record_array_connection.rb', line 52

def cursor_for(item)
  # item could be a batch loaded item. Sync it to have the id.
  cursor = { 'id' => Gitlab::Graphql::Lazy.force(item).id.to_s }
  encode(cursor.to_json)
end

#dupObject

Part of the implied interface for default objects for BatchLoader: objects must be clonable



59
60
61
62
63
64
65
66
67
68
# File 'lib/gitlab/graphql/pagination/active_record_array_connection.rb', line 59

def dup
  self.class.new(
    items.dup,
    first: first,
    after: after,
    max_page_size: max_page_size,
    last: last,
    before: before
  )
end

#next_page?Boolean Also known as: has_next_page

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
33
34
# File 'lib/gitlab/graphql/pagination/active_record_array_connection.rb', line 24

def next_page?
  load_nodes

  if before
    true
  elsif first
    limit_value < items.size
  else
    false
  end
end

#nodesObject



18
19
20
21
22
# File 'lib/gitlab/graphql/pagination/active_record_array_connection.rb', line 18

def nodes
  load_nodes

  @nodes
end

#previous_page?Boolean Also known as: has_previous_page

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gitlab/graphql/pagination/active_record_array_connection.rb', line 36

def previous_page?
  load_nodes

  if after
    true
  elsif last
    limit_value < items.size
  else
    false
  end
end