Class: GraphQL::Analysis::AST::QueryComplexity::ScopedTypeComplexity
- Inherits:
- 
      Object
      
        - Object
- GraphQL::Analysis::AST::QueryComplexity::ScopedTypeComplexity
 
- Defined in:
- lib/graphql/analysis/ast/query_complexity.rb
Constant Summary collapse
- HASH_CHILDREN =
          A single proc for #scoped_children hashes. Use this to avoid repeated allocations, since the lexical binding isn’t important. 
- ->(h, k) { h[k] = {} } 
Instance Attribute Summary collapse
- 
  
    
      #field_definition  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute field_definition. 
- 
  
    
      #nodes  ⇒ Array<GraphQL::Language::Nodes::Field> 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
- 
  
    
      #query  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute query. 
- 
  
    
      #response_path  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute response_path. 
Instance Method Summary collapse
- 
  
    
      #initialize(parent_type, field_definition, query, response_path)  ⇒ ScopedTypeComplexity 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of ScopedTypeComplexity. 
- 
  
    
      #own_complexity(child_complexity)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      #scoped_children  ⇒ Hash<Hash<Class => ScopedTypeComplexity>] 
    
    
  
  
  
  
  
  
  
  
  
    This value is only calculated when asked for to avoid needless hash allocations. 
- 
  
    
      #terminal?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Returns true if this field has no selections, ie, it’s a scalar. 
Constructor Details
#initialize(parent_type, field_definition, query, response_path) ⇒ ScopedTypeComplexity
Returns a new instance of ScopedTypeComplexity.
| 30 31 32 33 34 35 36 37 | # File 'lib/graphql/analysis/ast/query_complexity.rb', line 30 def initialize(parent_type, field_definition, query, response_path) @parent_type = parent_type @field_definition = field_definition @query = query @response_path = response_path @scoped_children = nil @nodes = [] end | 
Instance Attribute Details
#field_definition ⇒ Object (readonly)
Returns the value of attribute field_definition.
| 24 25 26 | # File 'lib/graphql/analysis/ast/query_complexity.rb', line 24 def field_definition @field_definition end | 
#nodes ⇒ Array<GraphQL::Language::Nodes::Field> (readonly)
| 40 41 42 | # File 'lib/graphql/analysis/ast/query_complexity.rb', line 40 def nodes @nodes end | 
#query ⇒ Object (readonly)
Returns the value of attribute query.
| 24 25 26 | # File 'lib/graphql/analysis/ast/query_complexity.rb', line 24 def query @query end | 
#response_path ⇒ Object (readonly)
Returns the value of attribute response_path.
| 24 25 26 | # File 'lib/graphql/analysis/ast/query_complexity.rb', line 24 def response_path @response_path end | 
Instance Method Details
#own_complexity(child_complexity) ⇒ Object
| 56 57 58 | # File 'lib/graphql/analysis/ast/query_complexity.rb', line 56 def own_complexity(child_complexity) @field_definition.calculate_complexity(query: @query, nodes: @nodes, child_complexity: child_complexity) end | 
#scoped_children ⇒ Hash<Hash<Class => ScopedTypeComplexity>]
This value is only calculated when asked for to avoid needless hash allocations. Also, if it’s never asked for, we determine that this scope complexity is a scalar field (#terminal?).
| 52 53 54 | # File 'lib/graphql/analysis/ast/query_complexity.rb', line 52 def scoped_children @scoped_children ||= Hash.new(&HASH_CHILDREN) end | 
#terminal? ⇒ Boolean
Returns true if this field has no selections, ie, it’s a scalar. We need a quick way to check whether we should continue traversing.
| 44 45 46 | # File 'lib/graphql/analysis/ast/query_complexity.rb', line 44 def terminal? @scoped_children.nil? end |