Class: GraphQL::Connections::Keyset::Base
- Defined in:
- lib/graphql/connections/keyset/base.rb
Overview
Base class for keyset pagination implementations
Constant Summary collapse
- SEPARATOR =
"/"
Instance Attribute Summary collapse
-
#field_key ⇒ Object
readonly
Returns the value of attribute field_key.
Attributes inherited from Base
Instance Method Summary collapse
- #cursor_for(item) ⇒ Object
-
#initialize(*args, keys:, separator: SEPARATOR, **kwargs) ⇒ Base
constructor
A new instance of Base.
Methods inherited from Base
#has_next_page, #has_previous_page, #nodes, #primary_key
Constructor Details
#initialize(*args, keys:, separator: SEPARATOR, **kwargs) ⇒ Base
Returns a new instance of Base.
12 13 14 15 16 17 |
# File 'lib/graphql/connections/keyset/base.rb', line 12 def initialize(*args, keys:, separator: SEPARATOR, **kwargs) @field_key, @primary_key = keys @separator = separator super(*args, **kwargs) end |
Instance Attribute Details
#field_key ⇒ Object (readonly)
Returns the value of attribute field_key.
8 9 10 |
# File 'lib/graphql/connections/keyset/base.rb', line 8 def field_key @field_key end |
Instance Method Details
#cursor_for(item) ⇒ Object
19 20 21 22 23 |
# File 'lib/graphql/connections/keyset/base.rb', line 19 def cursor_for(item) cursor = [item[field_key], item[primary_key]].map { |value| serialize(value) }.join(@separator) cursor = encode(cursor) if opaque_cursor cursor end |