Class: GraphQL::Analysis::AST::FieldUsage

Inherits:
Analyzer
  • Object
show all
Defined in:
lib/graphql/analysis/ast/field_usage.rb

Instance Method Summary collapse

Methods inherited from Analyzer

#analyze?, build_visitor_hooks

Constructor Details

#initialize(query) ⇒ FieldUsage

Returns a new instance of FieldUsage



6
7
8
9
10
# File 'lib/graphql/analysis/ast/field_usage.rb', line 6

def initialize(query)
  super
  @used_fields = Set.new
  @used_deprecated_fields = Set.new
end

Instance Method Details

#on_leave_field(parent, node, visitor) ⇒ Object



12
13
14
15
16
17
# File 'lib/graphql/analysis/ast/field_usage.rb', line 12

def on_leave_field(parent,  node, visitor)
  field_defn = visitor.field_definition
  field = "#{visitor.parent_type_definition.name}.#{field_defn.name}"
  @used_fields << field
  @used_deprecated_fields << field if field_defn.deprecation_reason
end

#resultObject



19
20
21
22
23
24
# File 'lib/graphql/analysis/ast/field_usage.rb', line 19

def result
  {
    used_fields: @used_fields.to_a,
    used_deprecated_fields: @used_deprecated_fields.to_a
  }
end