Class: GraphQL::Analysis::QueryComplexity::TypeComplexity

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/analysis/query_complexity.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initializeTypeComplexity

Returns a new instance of TypeComplexity.



72
73
74
# File 'lib/graphql/analysis/query_complexity.rb', line 72

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

Instance Method Details

#max_possible_complexityObject

Return the max possible complexity for types in this selection



77
78
79
# File 'lib/graphql/analysis/query_complexity.rb', line 77

def max_possible_complexity
  @types.each_value.max || 0
end

#merge(type_defn, complexity) ⇒ Object

Store the complexity for the branch on type_defn. Later we will see if this is the max complexity among branches.



83
84
85
# File 'lib/graphql/analysis/query_complexity.rb', line 83

def merge(type_defn, complexity)
  @types[type_defn] += complexity
end