Class: RuboCop::Cop::GraphQL::Overfetch::OverfetchVisitor

Inherits:
GraphQL::Language::Visitor
  • Object
show all
Defined in:
lib/rubocop/cop/graphql/overfetch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc, &range_for_line) ⇒ OverfetchVisitor

Returns a new instance of OverfetchVisitor.



50
51
52
53
54
55
56
# File 'lib/rubocop/cop/graphql/overfetch.rb', line 50

def initialize(doc, &range_for_line)
  super(doc)
  @range_for_line = range_for_line
  @fields = {}
  @aliases = {}
  @ranges = {}
end

Instance Attribute Details

#aliasesObject (readonly)

Returns the value of attribute aliases.



58
59
60
# File 'lib/rubocop/cop/graphql/overfetch.rb', line 58

def aliases
  @aliases
end

#fieldsObject (readonly)

Returns the value of attribute fields.



58
59
60
# File 'lib/rubocop/cop/graphql/overfetch.rb', line 58

def fields
  @fields
end

#rangesObject (readonly)

Returns the value of attribute ranges.



58
59
60
# File 'lib/rubocop/cop/graphql/overfetch.rb', line 58

def ranges
  @ranges
end

Instance Method Details

#on_field(node, parent) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/rubocop/cop/graphql/overfetch.rb', line 60

def on_field(node, parent)
  name = node.alias || node.name
  fields[name] ||= 0
  field_aliases(name).each { |n| (aliases[n] ||= []) << name }
  ranges[name] ||= @range_for_line.call(node.line)
  super
end