Sha256: 5a6a1f7898220bea3b97478e90853d4e5120345e99172f254833550463bdf9de

Contents?: true

Size: 932 Bytes

Versions: 7

Compression:

Stored size: 932 Bytes

Contents

# frozen_string_literal: true
module GraphQL
  module Relay
    class ConnectionResolve
      def initialize(field, underlying_resolve, max_page_size: nil)
        @field = field
        @underlying_resolve = underlying_resolve
        @max_page_size = max_page_size
      end

      def call(obj, args, ctx)
        nodes = @underlying_resolve.call(obj, args, ctx)
        if ctx.schema.lazy?(nodes)
          @field.prepare_lazy(nodes, args, ctx).then { |resolved_nodes|
            build_connection(resolved_nodes, args, obj, ctx)
          }
        else
          build_connection(nodes, args, obj, ctx)
        end
      end

      private

      def build_connection(nodes, args, parent, ctx)
        connection_class = GraphQL::Relay::BaseConnection.connection_for_nodes(nodes)
        connection_class.new(nodes, args, field: @field, max_page_size: @max_page_size, parent: parent, context: ctx)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
graphql-1.4.5 lib/graphql/relay/connection_resolve.rb
graphql-1.4.4 lib/graphql/relay/connection_resolve.rb
graphql-1.4.3 lib/graphql/relay/connection_resolve.rb
graphql-1.4.2 lib/graphql/relay/connection_resolve.rb
graphql-1.4.1 lib/graphql/relay/connection_resolve.rb
graphql-1.4.0 lib/graphql/relay/connection_resolve.rb
graphql-1.3.0 lib/graphql/relay/connection_resolve.rb