Class: ShopifyAPI::GraphQL::Pager
- Inherits:
-
Object
- Object
- ShopifyAPI::GraphQL::Pager
- Defined in:
- lib/shopify_api/graphql/tiny.rb
Overview
:nodoc:
Constant Summary collapse
- NEXT_PAGE_KEYS =
{ :before => %w[hasPreviousPage startCursor].freeze, :after => %w[hasNextPage endCursor].freeze }.freeze
Instance Method Summary collapse
- #execute(q, variables = nil) ⇒ Object
-
#initialize(gql, *options) ⇒ Pager
constructor
A new instance of Pager.
Constructor Details
#initialize(gql, *options) ⇒ Pager
Returns a new instance of Pager.
228 229 230 231 |
# File 'lib/shopify_api/graphql/tiny.rb', line 228 def initialize(gql, *) @gql = gql @options = () end |
Instance Method Details
#execute(q, variables = nil) ⇒ Object
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/shopify_api/graphql/tiny.rb', line 233 def execute(q, variables = nil) unless pagination_variable_exists?(q) raise ArgumentError, "query does not contain the pagination variable '#{@options[:variable]}'" end variables ||= {} pagination_finder = @options[@options[:direction]] loop do page = @gql.execute(q, variables) yield page cursor = pagination_finder[page] break unless cursor next_page_variables = variables.dup next_page_variables[@options[:variable]] = cursor #break unless next_page_variables != variables variables = next_page_variables end end |