class GraphQL::Analysis::QueryComplexity::TypeComplexity

Find the maximum possible complexity among those combinations.
Selections on an object may apply differently depending on what is actually returned by the resolve function.

def initialize

def initialize
  @types = Hash.new { |h, k| h[k] = 0 }
end

def max_possible_complexity

Return the max possible complexity for types in this selection
def max_possible_complexity
  max_complexity = 0
  @types.each do |type_defn, own_complexity|
    type_complexity = @types.reduce(0) do |memo, (other_type, other_complexity)|
      if types_overlap?(type_defn, other_type)
        memo + other_complexity
      else
        memo
      end
    end
    if type_complexity > max_complexity
      max_complexity = type_complexity
    end
  end
  max_complexity
end

def merge(definitions, complexity)

Store the complexity score for each of `types`
def merge(definitions, complexity)
  definitions.each { |type_defn, field_defn| @types[type_defn] += complexity }
end

def types_overlap?(type_1, type_2)

- type_1 is a member of type_2's possible types
- type_1 is type_2
True if:
def types_overlap?(type_1, type_2)
  if type_1 == type_2
    true
  elsif type_2.kind.union?
    type_2.include?(type_1)
  elsif type_1.kind.object? && type_2.kind.interface?
    type_1.interfaces.include?(type_2)
  else
    false
  end
end