Class: GraphQL::Analysis::FieldUsage
- Defined in:
- lib/graphql/analysis/field_usage.rb
Instance Method Summary collapse
-
#initialize(query) ⇒ FieldUsage
constructor
A new instance of FieldUsage.
- #on_leave_field(node, parent, visitor) ⇒ Object
- #result ⇒ Object
Methods inherited from Analyzer
Constructor Details
#initialize(query) ⇒ FieldUsage
Returns a new instance of FieldUsage.
5 6 7 8 9 10 11 |
# File 'lib/graphql/analysis/field_usage.rb', line 5 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
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/graphql/analysis/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, 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 |
#result ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/graphql/analysis/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, used_deprecated_enum_values: @used_deprecated_enum_values.to_a, } end |