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 66
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 72
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
rescue GraphQL::UnauthorizedError => err
  ctx.schema.unauthorized_object(err)
end

Private Instance Methods

proxy_to_depth(inner_obj, depth, ctx) click to toggle source
# File lib/graphql/schema/member/instrumentation.rb, line 86
def proxy_to_depth(inner_obj, depth, ctx)
  if depth > 0
    inner_obj.map { |i| proxy_to_depth(i, depth - 1, ctx) }
  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