Module: Eco::API::UseCases::GraphQL::Helpers::Base::ConnectionReader
- Includes:
- Enumerable
- 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
-
#each {|node| ... } ⇒ Enumerator
Iterate over every node across all pages (lazy — one network page at a time).
-
#page_size ⇒ Integer
Nodes fetched per page.
- #page_size=(size) ⇒ Object
-
#to_a(limit: nil) ⇒ Array
Materialise a bounded number of nodes without draining the whole connection.
Instance Method Details
#each {|node| ... } ⇒ Enumerator
Iterate over every node across all pages (lazy — one network page at a time).
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_size ⇒ Integer
Returns 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
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.
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 |