Class: RuboCop::Cop::GraphQL::MaxDepthSchema

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/graphql/max_depth_schema.rb

Overview

Detects missing max_depth configuration in schema files

Examples:

# good

class AppSchema < BaseSchema
  max_depth 42
end

Constant Summary collapse

MSG =
"max_depth should be configured for schema."

Instance Method Summary collapse

Instance Method Details

#max_depth(node) ⇒ Object



17
18
19
# File 'lib/rubocop/cop/graphql/max_depth_schema.rb', line 17

def_node_matcher :max_depth, <<~PATTERN
  `(send nil? :max_depth ...)
PATTERN

#on_class(node) ⇒ Object



23
24
25
26
27
# File 'lib/rubocop/cop/graphql/max_depth_schema.rb', line 23

def on_class(node)
  return if ::RuboCop::GraphQL::Class.new(node).nested? || max_depth(node)

  add_offense(node)
end