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
21
22
23
24
# 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
  arguments = visitor.query.arguments_for(node, visitor.field_definition)
  # 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



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

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