class GraphQL::Schema::Member::Instrumentation::ProxiedResolve
def call(obj, args, ctx)
def call(obj, args, ctx) result = @inner_resolve.call(obj, args, ctx) if ctx.skip == result || ctx.schema.lazy?(result) || result.nil? || execution_errors?(result) || ctx.wrapped_object result else ctx.wrapped_object = true proxy_to_depth(result, @list_depth, ctx) end end
def execution_errors?(result)
def execution_errors?(result) result.is_a?(GraphQL::ExecutionError) || (result.is_a?(Array) && result.any? && result.all? { |v| v.is_a?(GraphQL::ExecutionError) }) end
def initialize(inner_resolve:, list_depth:, inner_return_type:)
def initialize(inner_resolve:, list_depth:, inner_return_type:) @inner_resolve = inner_resolve @inner_return_type = inner_return_type @list_depth = list_depth end
def proxy_to_depth(inner_obj, depth, ctx)
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_or_lazy = 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 # .resolve_type may have returned a lazy ctx.schema.after_lazy(concrete_type_or_lazy) do |concrete_type| 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 end