Class: GraphQL::Analysis::FieldUsage
- Inherits:
-
Object
- Object
- GraphQL::Analysis::FieldUsage
- Defined in:
- lib/graphql/analysis/field_usage.rb
Overview
A query reducer for tracking both field usage and deprecated field usage.
Instance Method Summary collapse
-
#call(memo, visit_type, irep_node) ⇒ Object
-
#final_value(memo) ⇒ Object
-
#initial_value(query) ⇒ Object
-
#initialize(&block) ⇒ FieldUsage
constructor
A new instance of FieldUsage.
Constructor Details
#initialize(&block) ⇒ FieldUsage
Returns a new instance of FieldUsage
16 17 18 |
# File 'lib/graphql/analysis/field_usage.rb', line 16 def initialize(&block) @field_usage_handler = block end |
Instance Method Details
#call(memo, visit_type, irep_node) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/graphql/analysis/field_usage.rb', line 28 def call(memo, visit_type, irep_node) if irep_node.ast_node.is_a?(GraphQL::Language::Nodes::Field) && visit_type == :leave field = "#{irep_node.owner_type.name}.#{irep_node.definition.name}" memo[:used_fields] << field if irep_node.definition.deprecation_reason memo[:used_deprecated_fields] << field end end memo end |
#final_value(memo) ⇒ Object
40 41 42 |
# File 'lib/graphql/analysis/field_usage.rb', line 40 def final_value(memo) @field_usage_handler.call(memo[:query], memo[:used_fields].to_a, memo[:used_deprecated_fields].to_a) end |
#initial_value(query) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/graphql/analysis/field_usage.rb', line 20 def initial_value(query) { query: query, used_fields: Set.new, used_deprecated_fields: Set.new } end |