Method: GraphQL::Analysis::QueryDepth#call

Defined in:
lib/graphql/analysis/query_depth.rb

#call(memo, visit_type, irep_node) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/graphql/analysis/query_depth.rb', line 25

def call(memo, visit_type, irep_node)
  if irep_node.ast_node.is_a?(GraphQL::Language::Nodes::Field)
    # Don't validate introspection fields or skipped nodes
    not_validated_node = GraphQL::Schema::DYNAMIC_FIELDS.include?(irep_node.definition_name)
    if visit_type == :enter
      if not_validated_node
        memo[:skip_depth] += 1
      elsif memo[:skip_depth] > 0
        # we're inside an introspection query or skipped node
      else
        memo[:current_depth] += 1
      end
    else
      if not_validated_node
        memo[:skip_depth] -= 1
      else
        if memo[:max_depth] < memo[:current_depth]
          memo[:max_depth] = memo[:current_depth]
        end
        memo[:current_depth] -= 1
      end
    end
  end
  memo
end