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.



32
33
34
# File 'lib/graphql-hive/analyzer.rb', line 32

def used_fields
  @used_fields
end

Instance Method Details

#on_leave_argument(node, parent, visitor) ⇒ Object



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

def on_leave_argument(node, parent, visitor)
  @used_fields.add([visitor.parent_type_definition.graphql_name, parent.name, node.name].join('.'))

  arg_type = visitor.argument_definition.type.unwrap
  arg_type_kind = visitor.argument_definition.type.unwrap.kind
  if arg_type_kind.input_object?
    @used_fields.add(arg_type.graphql_name)
    arg_type.arguments.each do |arg|
      @used_fields.add([arg_type.graphql_name, arg[0]].join('.'))
    end
  elsif arg_type_kind.enum?
    @used_fields.add([arg_type.graphql_name, node.value.name].join('.'))
  end
end

#on_leave_field(node, _parent, visitor) ⇒ Object



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

def on_leave_field(node, _parent, visitor)
  @used_fields.add(visitor.parent_type_definition.graphql_name)
  @used_fields.add([visitor.parent_type_definition.graphql_name, node.name].join('.'))
end

#resultObject



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

def result
  @used_fields
end