Sha256: 8952e6565c622eb4ad9a48eca5905ee21b6808ee529a82194b6cd24165f7fa4c

Contents?: true

Size: 1.29 KB

Versions: 16

Compression:

Stored size: 1.29 KB

Contents

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

      def call(obj, args, ctx)
        # in a lazy ressolve hook, obj is the promise,
        # get the object that the promise was
        # originally derived from
        parent = ctx.object

        nodes = @underlying_resolve.call(obj, args, ctx)

        if nodes.nil? || ctx.schema.lazy?(nodes) || nodes.is_a?(GraphQL::Execution::Execute::Skip) || ctx.wrapped_connection
          nodes
        else
          ctx.wrapped_connection = true
          build_connection(nodes, args, parent, ctx)
        end
      end

      private

      def build_connection(nodes, args, parent, ctx)
        if nodes.is_a? GraphQL::ExecutionError
          ctx.add_error(nodes)
          nil
        else
          if parent.is_a?(GraphQL::Schema::Object)
            parent = parent.object
          end
          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
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
graphql-1.8.18 lib/graphql/relay/connection_resolve.rb
graphql-1.8.17 lib/graphql/relay/connection_resolve.rb
graphql-1.8.16 lib/graphql/relay/connection_resolve.rb
graphql-1.8.15 lib/graphql/relay/connection_resolve.rb
graphql-1.8.14 lib/graphql/relay/connection_resolve.rb
graphql-1.8.13 lib/graphql/relay/connection_resolve.rb
graphql-1.8.12 lib/graphql/relay/connection_resolve.rb
graphql-1.9.0.pre1 lib/graphql/relay/connection_resolve.rb
graphql-1.8.11 lib/graphql/relay/connection_resolve.rb
graphql-1.8.10 lib/graphql/relay/connection_resolve.rb
graphql-1.8.9 lib/graphql/relay/connection_resolve.rb
graphql-1.8.8 lib/graphql/relay/connection_resolve.rb
graphql-1.8.7 lib/graphql/relay/connection_resolve.rb
graphql-1.8.6 lib/graphql/relay/connection_resolve.rb
graphql-1.8.5 lib/graphql/relay/connection_resolve.rb
graphql-1.8.4 lib/graphql/relay/connection_resolve.rb