Class: GraphQL::Hive::Analyzer

Inherits:
Analysis::AST::Analyzer
  • Object
show all
Defined in:
lib/graphql-hive/analyzer.rb

Overview

Fetch all users fields, input objects and enums

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query_or_multiplex) ⇒ Analyzer

Returns a new instance of Analyzer.



7
8
9
10
# File 'lib/graphql-hive/analyzer.rb', line 7

def initialize(query_or_multiplex)
  super
  @used_fields = Set.new
end

Instance Attribute Details

#used_fieldsObject (readonly)

Returns the value of attribute used_fields.



35
36
37
# File 'lib/graphql-hive/analyzer.rb', line 35

def used_fields
  @used_fields
end

Instance Method Details

#on_enter_argument(node, parent, visitor) ⇒ Object

Visitor also calls ‘on_enter_argument’ when visiting input object fields in arguments



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/graphql-hive/analyzer.rb', line 18

def on_enter_argument(node, parent, visitor)
  arg_type = visitor.argument_definition.type.unwrap
  @used_fields.add(arg_type.graphql_name)

  # collect field argument path
  # input object fields won't have a "parent.name" method available
  if parent.respond_to?(:name)
    @used_fields.add(make_id(visitor.parent_type_definition.graphql_name, parent.name, node.name))
  end

  if arg_type.kind.input_object?
    collect_input_object_fields(node, arg_type)
  elsif arg_type.kind.enum?
    collect_enum_values(node, arg_type)
  end
end

#on_enter_field(node, _parent, visitor) ⇒ Object



12
13
14
15
# File 'lib/graphql-hive/analyzer.rb', line 12

def on_enter_field(node, _parent, visitor)
  @used_fields.add(visitor.parent_type_definition.graphql_name)
  @used_fields.add(make_id(visitor.parent_type_definition.graphql_name, node.name))
end

#resultObject



37
38
39
# File 'lib/graphql-hive/analyzer.rb', line 37

def result
  @used_fields
end