Class: GraphQL::Analysis::AST::QueryDepth
- Defined in:
- lib/graphql/analysis/ast/query_depth.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(query) ⇒ QueryDepth
constructor
A new instance of QueryDepth.
- #on_enter_field(node, parent, visitor) ⇒ Object
- #on_leave_field(node, parent, visitor) ⇒ Object
- #result ⇒ Object
Methods inherited from Analyzer
Constructor Details
#initialize(query) ⇒ QueryDepth
Returns a new instance of QueryDepth.
28 29 30 31 32 33 |
# File 'lib/graphql/analysis/ast/query_depth.rb', line 28 def initialize(query) @max_depth = 0 @current_depth = 0 @count_introspection_fields = query.schema.count_introspection_fields super end |
Instance Method Details
#on_enter_field(node, parent, visitor) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/graphql/analysis/ast/query_depth.rb', line 35 def on_enter_field(node, parent, visitor) return if visitor.skipping? || visitor.visiting_fragment_definition? || (@count_introspection_fields == false && visitor.field_definition.introspection?) @current_depth += 1 end |
#on_leave_field(node, parent, visitor) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/graphql/analysis/ast/query_depth.rb', line 43 def on_leave_field(node, parent, visitor) return if visitor.skipping? || visitor.visiting_fragment_definition? || (@count_introspection_fields == false && visitor.field_definition.introspection?) if @max_depth < @current_depth @max_depth = @current_depth end @current_depth -= 1 end |
#result ⇒ Object
54 55 56 |
# File 'lib/graphql/analysis/ast/query_depth.rb', line 54 def result @max_depth end |