Class: RuboCop::Cop::GraphQL::Overfetch::OverfetchVisitor
- Inherits:
-
GraphQL::Language::Visitor
- Object
- GraphQL::Language::Visitor
- RuboCop::Cop::GraphQL::Overfetch::OverfetchVisitor
- Defined in:
- lib/rubocop/cop/graphql/overfetch.rb
Instance Attribute Summary collapse
-
#aliases ⇒ Object
readonly
Returns the value of attribute aliases.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#ranges ⇒ Object
readonly
Returns the value of attribute ranges.
Instance Method Summary collapse
-
#initialize(doc, &range_for_line) ⇒ OverfetchVisitor
constructor
A new instance of OverfetchVisitor.
- #on_field(node, parent) ⇒ Object
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
#aliases ⇒ Object (readonly)
Returns the value of attribute aliases.
58 59 60 |
# File 'lib/rubocop/cop/graphql/overfetch.rb', line 58 def aliases @aliases end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
58 59 60 |
# File 'lib/rubocop/cop/graphql/overfetch.rb', line 58 def fields @fields end |
#ranges ⇒ Object (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 |