Sha256: 2e1c63cab5006080bcb4d74d76ebf27e69798f5d220593ef4de809486a71d159

Contents?: true

Size: 1.23 KB

Versions: 7

Compression:

Stored size: 1.23 KB

Contents

module Ecoportal
  module API
    class GraphQL
      module Logic
        class QueryConnection < Ecoportal::API::GraphQL::Logic::Query
          accepted_params :searchConf, :after, :before, :first, :last
          include Enumerable

          def each(connection_block: nil, **kargs, &block)
            return to_enum(:each, **kargs, connection_block: connection_block) unless block
            cursor = nil
            loop do
              kargs.update(after: cursor) if cursor
              connection = query(**kargs, &connection_block)
              #total    = connection.totalCount
              page_info = connection.pageInfo
              connection.nodes.each(&block)
              break unless (cursor = page_info.endCursor)
            end
          end

          def response_class
            return connection_class if respond_to?(:connection_class)
            @response_class ||= self.class.new_class(
              item_class,
              inherits:  Ecoportal::API::GraphQL::Logic::Connection,
              namespace: "Ecoportal::API::GraphQL::Connection"
            ) do |klass|
              klass.item_class = item_class
            end
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ecoportal-api-graphql-0.4.3 lib/ecoportal/api/graphql/logic/query_connection.rb
ecoportal-api-graphql-0.4.2 lib/ecoportal/api/graphql/logic/query_connection.rb
ecoportal-api-graphql-0.4.1 lib/ecoportal/api/graphql/logic/query_connection.rb
ecoportal-api-graphql-0.4.0 lib/ecoportal/api/graphql/logic/query_connection.rb
ecoportal-api-graphql-0.3.16 lib/ecoportal/api/graphql/logic/query_connection.rb
ecoportal-api-graphql-0.3.15 lib/ecoportal/api/graphql/logic/query_connection.rb
ecoportal-api-graphql-0.3.14 lib/ecoportal/api/graphql/logic/query_connection.rb