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?, #visit?

Constructor Details

#initialize(query) ⇒ FieldUsage

Returns a new instance of FieldUsage.



6
7
8
9
10
11
12
# 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
  @used_deprecated_enum_values = Set.new
end

Instance Method Details

#on_leave_field(node, parent, visitor) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/graphql/analysis/ast/field_usage.rb', line 14

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
  arguments = visitor.query.arguments_for(node, field_defn)
  # If there was an error when preparing this argument object,
  # then this might be an error or something:
  if arguments.respond_to?(:argument_values)
    extract_deprecated_arguments(arguments.argument_values)
  end
end

#resultObject



27
28
29
30
31
32
33
34
# File 'lib/graphql/analysis/ast/field_usage.rb', line 27

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