Sha256: de0ff2b99a08335df2d62b563af2f6fac59a095cb27ee742ed6bd49b0a4fa299

Contents?: true

Size: 1.28 KB

Versions: 5

Compression:

Stored size: 1.28 KB

Contents

module Ecoportal
  module API
    class GraphQL
      module Base
        class QueryConnection < Ecoportal::API::GraphQL::Base::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; results = 0
            loop do
              kargs.update(after: cursor) if cursor
              connection = query(**kargs, &connection_block)
              #total    = connection.totalCount
              pageInfo = connection.pageInfo
              connection.nodes.each do |item|
                yield item
              end
              break unless cursor = pageInfo.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::Base::Connection,
              namespace: "Ecoportal::API::GraphQL::Connection"
            ) do |klass|
              klass.item_class = item_class
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ecoportal-api-graphql-0.1.11 lib/ecoportal/api/graphql/base/query_connection.rb
ecoportal-api-graphql-0.1.10 lib/ecoportal/api/graphql/base/query_connection.rb
ecoportal-api-graphql-0.1.9 lib/ecoportal/api/graphql/base/query_connection.rb
ecoportal-api-graphql-0.1.8 lib/ecoportal/api/graphql/base/query_connection.rb
ecoportal-api-graphql-0.1.7 lib/ecoportal/api/graphql/base/query_connection.rb