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
@return [Array<GraphQL::Language::Nodes::Field>]
Public Class Methods
@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
# 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
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
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