Sha256: 014109e88f01f01d75807332b29559078644725c2c8275c27df150db99f3fb52

Contents?: true

Size: 826 Bytes

Versions: 9

Compression:

Stored size: 826 Bytes

Contents

# frozen_string_literal: true
require "graphql/pagination/relation_connection"

module GraphQL
  module Pagination
    # Customizes `RelationConnection` to work with `ActiveRecord::Relation`s.
    class ActiveRecordRelationConnection < Pagination::RelationConnection
      def relation_count(relation)
        if relation.respond_to?(:unscope)
          relation.unscope(:order).count(:all)
        else
          # Rails 3
          relation.count
        end
      end

      def relation_limit(relation)
        relation.limit_value
      end

      def relation_offset(relation)
        relation.offset_value
      end

      def null_relation(relation)
        if relation.respond_to?(:none)
          relation.none
        else
          # Rails 3
          relation.where("1=2")
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
graphql-1.10.4 lib/graphql/pagination/active_record_relation_connection.rb
graphql-1.10.3 lib/graphql/pagination/active_record_relation_connection.rb
graphql-1.10.2 lib/graphql/pagination/active_record_relation_connection.rb
graphql-1.10.1 lib/graphql/pagination/active_record_relation_connection.rb
graphql-1.10.0 lib/graphql/pagination/active_record_relation_connection.rb
graphql-1.10.0.pre4 lib/graphql/pagination/active_record_relation_connection.rb
graphql-1.10.0.pre3 lib/graphql/pagination/active_record_relation_connection.rb
graphql-1.10.0.pre2 lib/graphql/pagination/active_record_relation_connection.rb
graphql-1.10.0.pre1 lib/graphql/pagination/active_record_relation_connection.rb