Sha256: c12e8af53f17ca54301beb9c11128dd7d77cc151f773953585cdebb3cae610bc

Contents?: true

Size: 1.52 KB

Versions: 118

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true
module GraphQL
  module Relay
    # A connection implementation to expose MongoDB collection objects.
    # It works for:
    # - `Mongoid::Criteria`
    class MongoRelationConnection < RelationConnection
      private

      def relation_offset(relation)
        relation.options.skip
      end

      def relation_limit(relation)
        relation.options.limit
      end

      def relation_count(relation)
        # Must perform query (hence #to_a) to count results https://jira.mongodb.org/browse/MONGOID-2325
        relation.to_a.count
      end

      def limit_nodes(sliced_nodes, limit)
        if limit == 0
          if sliced_nodes.respond_to?(:none) # added in Mongoid 4.0
            sliced_nodes.without_options.none
          else
            sliced_nodes.where(id: nil) # trying to simulate #none for 3.1.7
          end
        else
          sliced_nodes.limit(limit)
        end
      end
    end

    if defined?(Mongoid::Criteria)
      BaseConnection.register_connection_implementation(Mongoid::Criteria, MongoRelationConnection)
    end

    # Mongoid 5 and 6
    if defined?(Mongoid::Relations::Targets::Enumerable)
      BaseConnection.register_connection_implementation(Mongoid::Relations::Targets::Enumerable, MongoRelationConnection)
    end

    # Mongoid 7
    if defined?(Mongoid::Association::Referenced::HasMany::Targets::Enumerable)
      BaseConnection.register_connection_implementation(Mongoid::Association::Referenced::HasMany::Targets::Enumerable, MongoRelationConnection)
    end
  end
end

Version data entries

118 entries across 118 versions & 2 rubygems

Version Path
graphql-1.13.23 lib/graphql/relay/mongo_relation_connection.rb
graphql-1.13.22 lib/graphql/relay/mongo_relation_connection.rb
graphql-1.13.21 lib/graphql/relay/mongo_relation_connection.rb
graphql-1.13.20 lib/graphql/relay/mongo_relation_connection.rb
graphql-1.13.19 lib/graphql/relay/mongo_relation_connection.rb
graphql-1.13.18 lib/graphql/relay/mongo_relation_connection.rb
graphql-1.13.17 lib/graphql/relay/mongo_relation_connection.rb
graphql-1.13.16 lib/graphql/relay/mongo_relation_connection.rb
graphql-1.13.15 lib/graphql/relay/mongo_relation_connection.rb
graphql-1.13.14 lib/graphql/relay/mongo_relation_connection.rb
graphql-1.13.13 lib/graphql/relay/mongo_relation_connection.rb
graphql_cody-1.13.0 lib/graphql/relay/mongo_relation_connection.rb
graphql-1.13.12 lib/graphql/relay/mongo_relation_connection.rb
graphql-1.13.11 lib/graphql/relay/mongo_relation_connection.rb
graphql-1.13.10 lib/graphql/relay/mongo_relation_connection.rb
graphql-1.13.9 lib/graphql/relay/mongo_relation_connection.rb
graphql-1.12.24 lib/graphql/relay/mongo_relation_connection.rb
graphql-1.13.8 lib/graphql/relay/mongo_relation_connection.rb
graphql-1.13.7 lib/graphql/relay/mongo_relation_connection.rb
graphql-1.13.6 lib/graphql/relay/mongo_relation_connection.rb