Module: Eco::API::UseCases::GraphQL::Helpers::Base::ConnectionReader

Includes:
Enumerable
Included in:
AccessLogs::Base::Reader, Dashboards::Base::Reader, Pages::Activities::Reader
Defined in:
lib/eco/api/usecases/graphql/helpers/base/connection_reader.rb

Overview

Shared substrate for NATIVE GraphQL connection readers.

The gem's Logic::QueryConnection is already Enumerable and paginates lazily over first/after using pageInfo.endCursor/hasNextPage (see its #each). This mixin wraps that machinery behind a small, uniform reader surface so every native reader (access logs, page activities, dashboards, ...) exposes the same each / to_a / first(n) behaviour and a consistent page_size without re-implementing cursor pagination.

A concrete reader supplies a #query (a gem query object, e.g. graphql.currentOrganization.activityLogs) and the per-call filter/argument hash via #reader_params. Everything else (lazy iteration, batching, materialising) is inherited.

Constant Summary collapse

DEFAULT_PAGE_SIZE =

Default number of nodes fetched per network round-trip.

100

Instance Method Summary collapse

Instance Method Details

#each {|node| ... } ⇒ Enumerator

Iterate over every node across all pages (lazy — one network page at a time).

Yield Parameters:

  • node (Object)

    a gem read model (e.g. Model::ActivityLog / Model::Activity).

Returns:

  • (Enumerator)

    when no block is given.



22
23
24
25
26
# File 'lib/eco/api/usecases/graphql/helpers/base/connection_reader.rb', line 22

def each(&block)
  return to_enum(:each) unless block

  connection_query.each(**each_params, &block)
end

#page_sizeInteger

Returns nodes fetched per page.

Returns:

  • (Integer)

    nodes fetched per page.



38
39
40
# File 'lib/eco/api/usecases/graphql/helpers/base/connection_reader.rb', line 38

def page_size
  @page_size ||= DEFAULT_PAGE_SIZE
end

#page_size=(size) ⇒ Object

Parameters:

  • size (Integer)


43
44
45
# File 'lib/eco/api/usecases/graphql/helpers/base/connection_reader.rb', line 43

def page_size=(size)
  @page_size = Integer(size)
end

#to_a(limit: nil) ⇒ Array

Materialise a bounded number of nodes without draining the whole connection.

Parameters:

  • limit (Integer, nil) (defaults to: nil)

    maximum nodes to return; nil = all pages.

Returns:

  • (Array)


31
32
33
34
35
# File 'lib/eco/api/usecases/graphql/helpers/base/connection_reader.rb', line 31

def to_a(limit: nil)
  return super() if limit.nil?

  take(limit)
end