Class: GraphQL::Analysis::AST::QueryComplexity::TypeComplexity
- Inherits:
 - 
      Object
      
        
- Object
 - GraphQL::Analysis::AST::QueryComplexity::TypeComplexity
 
 
- 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
- 
  
    
      #initialize  ⇒ TypeComplexity 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of TypeComplexity.
 - 
  
    
      #max_possible_complexity  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Return the max possible complexity for types in this selection.
 - 
  
    
      #merge(type_defn, key, complexity)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Store the complexity for the branch on
type_defn. 
Constructor Details
#initialize ⇒ TypeComplexity
Returns a new instance of TypeComplexity
      95 96 97  | 
    
      # File 'lib/graphql/analysis/ast/query_complexity.rb', line 95 def initialize @types = Hash.new { |h, k| h[k] = {} } end  | 
  
Instance Method Details
#max_possible_complexity ⇒ Object
Return the max possible complexity for types in this selection
      100 101 102 103 104  | 
    
      # File 'lib/graphql/analysis/ast/query_complexity.rb', line 100 def max_possible_complexity @types.map do |type, fields| fields.values.inject(:+) 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.
      108 109 110  | 
    
      # File 'lib/graphql/analysis/ast/query_complexity.rb', line 108 def merge(type_defn, key, complexity) @types[type_defn][key] = complexity end  |