Module: GraphQL::Schema::ResolveTypeWithType

Defined in:
lib/graphql/schema.rb

Overview

rubocop:disable Lint/DuplicateMethods

Instance Method Summary collapse

Instance Method Details

#resolve_type(type, obj, ctx) ⇒ Object



1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
# File 'lib/graphql/schema.rb', line 1087

def resolve_type(type, obj, ctx)
  maybe_lazy_resolve_type_result = if type.is_a?(Module) && type.respond_to?(:resolve_type)
    type.resolve_type(obj, ctx)
  else
    super
  end

  after_lazy(maybe_lazy_resolve_type_result) do |resolve_type_result|
    if resolve_type_result.is_a?(Array) && resolve_type_result.size == 2
      resolved_type = resolve_type_result[0]
      resolved_value = resolve_type_result[1]
    else
      resolved_type = resolve_type_result
      resolved_value = obj
    end

    if resolved_type.nil? || (resolved_type.is_a?(Module) && resolved_type.respond_to?(:kind))
      [resolved_type, resolved_value]
    else
      raise ".resolve_type should return a type definition, but got #{resolved_type.inspect} (#{resolved_type.class}) from `resolve_type(#{type}, #{obj}, #{ctx})`"
    end
  end
end