Class: GraphQL::Analysis::AST::QueryComplexity::AbstractTypeComplexity

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/analysis/ast/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

#initializeAbstractTypeComplexity

Returns a new instance of AbstractTypeComplexity



88
89
90
# File 'lib/graphql/analysis/ast/query_complexity.rb', line 88

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

Instance Method Details

#max_possible_complexityObject

Return the max possible complexity for types in this selection



93
94
95
96
97
98
99
100
# File 'lib/graphql/analysis/ast/query_complexity.rb', line 93

def max_possible_complexity
  max = 0
  @types.each_value do |fields|
    complexity = fields.each_value.inject(:+)
    max = complexity if complexity > max
  end
  max
end

#merge(type_defn, key, complexity) ⇒ Object

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



104
105
106
# File 'lib/graphql/analysis/ast/query_complexity.rb', line 104

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