class GraphQL::Analysis::AST::QueryComplexity::ScopedTypeComplexity

Constants

HASH_CHILDREN

A single proc for {#scoped_children} hashes. Use this to avoid repeated allocations, since the lexical binding isn't important.

Attributes

field_definition[R]
nodes[R]

@return [Array<GraphQL::Language::Nodes::Field>]

query[R]
response_path[R]

Public Class Methods

new(parent_type, field_definition, query, response_path) click to toggle source

@param parent_type [Class] The owner of `field_definition` @param field_definition [GraphQL::Field, GraphQL::Schema::Field] Used for getting the `.complexity` configuration @param query [GraphQL::Query] Used for `query.possible_types` @param response_path [Array<String>] The path to the response key for the field

# 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

Public Instance Methods

own_complexity(child_complexity) click to toggle source
# 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() click to toggle source

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?}). @return [Hash<Hash<Class => ScopedTypeComplexity>]

# File lib/graphql/analysis/ast/query_complexity.rb, line 52
def scoped_children
  @scoped_children ||= Hash.new(&HASH_CHILDREN)
end
terminal?() click to toggle source

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.

# File lib/graphql/analysis/ast/query_complexity.rb, line 44
def terminal?
  @scoped_children.nil?
end