Sha256: b1793a915ad0f03859f9c9ec23e2be714bebf104652fe24a81c37a88575e8ec7

Contents?: true

Size: 761 Bytes

Versions: 13

Compression:

Stored size: 761 Bytes

Contents

module GraphQL
  module Models
    class PromiseRelationConnection < GraphQL::Relay::RelationConnection
      def edges
        # Can't do any optimization if the request is asking for the last X items, since there's
        # no easy way to turn it into a generalized query.
        return super if last

        relation = sliced_nodes
        limit = [first, last, max_page_size].compact.min
        relation = relation.limit(limit) if first
        request = RelationLoadRequest.new(relation)

        request.load.then do |models|
          models.map { |m| GraphQL::Relay::Edge.new(m, self) }
        end
      end
    end

    GraphQL::Relay::BaseConnection.register_connection_implementation(ActiveRecord::Relation, PromiseRelationConnection)
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
graphql-activerecord-0.6.0 lib/graphql/models/promise_relation_connection.rb
graphql-activerecord-0.5.6 lib/graphql/models/promise_relation_connection.rb
graphql-activerecord-0.5.5 lib/graphql/models/promise_relation_connection.rb
graphql-activerecord-0.5.4 lib/graphql/models/promise_relation_connection.rb
graphql-activerecord-0.5.3 lib/graphql/models/promise_relation_connection.rb
graphql-activerecord-0.5.2 lib/graphql/models/promise_relation_connection.rb
graphql-activerecord-0.5.1 lib/graphql/models/promise_relation_connection.rb
graphql-activerecord-0.5.0 lib/graphql/models/promise_relation_connection.rb
graphql-activerecord-0.4.3 lib/graphql/models/promise_relation_connection.rb
graphql-activerecord-0.4.2 lib/graphql/models/promise_relation_connection.rb
graphql-activerecord-0.4.1 lib/graphql/models/promise_relation_connection.rb
graphql-activerecord-0.4.0 lib/graphql/models/promise_relation_connection.rb
graphql-activerecord-0.3.1 lib/graphql/models/promise_relation_connection.rb