class GraphQL::Schema::Member::Instrumentation::ProxiedResolve

Public Class Methods

new(inner_resolve:, list_depth:, inner_return_type:) click to toggle source
# File lib/graphql/schema/member/instrumentation.rb, line 67
def initialize(inner_resolve:, list_depth:, inner_return_type:)
  @inner_resolve = inner_resolve
  @inner_return_type = inner_return_type
  @list_depth = list_depth
end

Public Instance Methods

call(obj, args, ctx) click to toggle source
# File lib/graphql/schema/member/instrumentation.rb, line 73
def call(obj, args, ctx)
  result = @inner_resolve.call(obj, args, ctx)
  if ctx.skip == result || ctx.schema.lazy?(result) || result.nil? || result.is_a?(GraphQL::ExecutionError) || ctx.wrapped_object
    result
  else
    ctx.wrapped_object = true
    proxy_to_depth(result, @list_depth, ctx)
  end
end

Private Instance Methods

proxy_to_depth(inner_obj, depth, ctx) click to toggle source
# File lib/graphql/schema/member/instrumentation.rb, line 85
def proxy_to_depth(inner_obj, depth, ctx)
  if depth > 0
    inner_obj.map { |i| proxy_to_depth(i, depth - 1, ctx) }
  else
    ctx.schema.after_lazy(inner_obj) do |inner_obj|
      if inner_obj.nil?
        # For lists with nil, we need another nil check here
        nil
      else
        concrete_type = case @inner_return_type
        when GraphQL::UnionType, GraphQL::InterfaceType
          ctx.query.resolve_type(@inner_return_type, inner_obj)
        when GraphQL::ObjectType
          @inner_return_type
        else
          raise "unexpected proxying type #{@inner_return_type} for #{inner_obj} at #{ctx.owner_type}.#{ctx.field.name}"
        end

        if concrete_type && (object_class = concrete_type.metadata[:type_class])
          # use the query-level context here, since it won't be field-specific anyways
          query_ctx = ctx.query.context
          object_class.authorized_new(inner_obj, query_ctx)
        else
          inner_obj
        end
      end
    end
  end
end