Class: GraphQL::Analysis::QueryComplexity::ScopedTypeComplexity

Inherits:
Hash
  • Object
show all
Defined in:
lib/graphql/analysis/query_complexity.rb

Overview

ScopedTypeComplexity models a tree of GraphQL types mapped to inner selections, ie: Hash<GraphQL::BaseType, Hash<String, ScopedTypeComplexity>>

Constant Summary collapse

DEFAULT_PROC =

A proc for defaulting empty namespace requests as a new scope hash.

->(h, k) { h[k] = {} }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent_type, field_definition, query, response_path) ⇒ ScopedTypeComplexity

Parameters

  • parent_type (Class) — The owner of field_definition
  • field_definition (GraphQL::Field, GraphQL::Schema::Field) — Used for getting the .complexity configuration
  • query (GraphQL::Query) — Used for query.possible_types
  • response_path (Array<String>) — The path to the response key for the field

Returns

  • Hash<GraphQL::BaseType, Hash<String, ScopedTypeComplexity>>

:call-seq:

initialize(Class parent_type, GraphQL::Field | GraphQL::Schema::Field field_definition, GraphQL::Query query, Array[String] response_path) -> Hash[GraphQL::BaseType, Hash[String, ScopedTypeComplexity]]


69
70
71
72
73
74
75
76
# File 'lib/graphql/analysis/query_complexity.rb', line 69

def initialize(parent_type, field_definition, query, response_path)
  super(&DEFAULT_PROC)
  @parent_type = parent_type
  @field_definition = field_definition
  @query = query
  @response_path = response_path
  @nodes = []
end

Instance Attribute Details

#field_definition ⇒ Object (readonly)

Returns the value of attribute field_definition.



54
55
56
# File 'lib/graphql/analysis/query_complexity.rb', line 54

def field_definition
  @field_definition
end

#nodes ⇒ Object (readonly)

Returns

  • Array<GraphQL::Language::Nodes::Field>


81
82
83
# File 'lib/graphql/analysis/query_complexity.rb', line 81

def nodes
  @nodes
end

#query ⇒ Object (readonly)

Returns the value of attribute query.



54
55
56
# File 'lib/graphql/analysis/query_complexity.rb', line 54

def query
  @query
end

#response_path ⇒ Object (readonly)

Returns the value of attribute response_path.



54
55
56
# File 'lib/graphql/analysis/query_complexity.rb', line 54

def response_path
  @response_path
end

Instance Method Details

#composite? ⇒ Boolean

Returns:

  • (Boolean)


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

def composite?
  !empty?
end

#own_complexity(child_complexity) ⇒ Object



83
84
85
# File 'lib/graphql/analysis/query_complexity.rb', line 83

def own_complexity(child_complexity)
  @field_definition.calculate_complexity(query: @query, nodes: @nodes, child_complexity: child_complexity)
end