class GraphQL::Analysis::AST::QueryDepth

Public Class Methods

new(query) click to toggle source
Calls superclass method GraphQL::Analysis::AST::Analyzer::new
# File lib/graphql/analysis/ast/query_depth.rb, line 28
def initialize(query)
  @max_depth = 0
  @current_depth = 0
  super
end

Public Instance Methods

on_enter_field(node, parent, visitor) click to toggle source
# File lib/graphql/analysis/ast/query_depth.rb, line 34
def on_enter_field(node, parent, visitor)
  return if visitor.skipping? || visitor.visiting_fragment_definition?

  @current_depth += 1
end
on_leave_field(node, parent, visitor) click to toggle source
# File lib/graphql/analysis/ast/query_depth.rb, line 40
def on_leave_field(node, parent, visitor)
  return if visitor.skipping? || visitor.visiting_fragment_definition?

  if @max_depth < @current_depth
    @max_depth = @current_depth
  end
  @current_depth -= 1
end
result() click to toggle source
# File lib/graphql/analysis/ast/query_depth.rb, line 49
def result
  @max_depth
end