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?

Constructor Details

#initialize(query) ⇒ FieldUsage

Returns a new instance of FieldUsage.



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

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

Instance Method Details

#on_leave_field(node, parent, visitor) ⇒ Object



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

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

  extract_deprecated_arguments(visitor.query.arguments_for(node, visitor.field_definition).argument_values)
end

#resultObject



22
23
24
25
26
27
28
# File 'lib/graphql/analysis/ast/field_usage.rb', line 22

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