module GraphQL::Schema::Member::Instrumentation

Public Instance Methods

after_query(_query) click to toggle source
# File lib/graphql/schema/member/instrumentation.rb, line 35
def after_query(_query)
end
apply_proxy(field) click to toggle source
# File lib/graphql/schema/member/instrumentation.rb, line 42
def apply_proxy(field)
  resolve_proc = field.resolve_proc
  lazy_resolve_proc = field.lazy_resolve_proc
  inner_return_type = field.type.unwrap
  depth = list_depth(field.type)

  field.redefine(
    resolve: ProxiedResolve.new(inner_resolve: resolve_proc, list_depth: depth, inner_return_type: inner_return_type),
    lazy_resolve: ProxiedResolve.new(inner_resolve: lazy_resolve_proc, list_depth: depth, inner_return_type: inner_return_type),
  )
end
before_query(query) click to toggle source
# File lib/graphql/schema/member/instrumentation.rb, line 19
def before_query(query)
  # Get the root type for this query
  root_node = query.irep_selection
  if root_node.nil?
    # It's an invalid query, nothing to do here
  else
    root_type = query.irep_selection.return_type
    # If it has a wrapper, apply it
    wrapper_class = root_type.metadata[:type_class]
    if wrapper_class
      new_root_value = wrapper_class.authorized_new(query.root_value, query.context)
      query.root_value = new_root_value
    end
  end
end
instrument(type, field) click to toggle source
# File lib/graphql/schema/member/instrumentation.rb, line 8
def instrument(type, field)
  return_type = field.type.unwrap
  if (return_type.is_a?(GraphQL::ObjectType) && return_type.metadata[:type_class]) ||
      return_type.is_a?(GraphQL::InterfaceType) ||
      (return_type.is_a?(GraphQL::UnionType) && return_type.possible_types.any? { |t| t.metadata[:type_class] })
    field = apply_proxy(field)
  end

  field
end
list_depth(type, starting_at = 0) click to toggle source
# File lib/graphql/schema/member/instrumentation.rb, line 54
def list_depth(type, starting_at = 0)
  case type
  when GraphQL::ListType
    list_depth(type.of_type, starting_at + 1)
  when GraphQL::NonNullType
    list_depth(type.of_type, starting_at)
  else
    starting_at
  end
end