Class: GraphQLMetrics::Extractor

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql_metrics/extractor.rb

Defined Under Namespace

Classes: DummyInstrumentor

Constant Summary collapse

EXPLICIT_NULL =
'EXPLICIT_NULL'
IMPLICIT_NULL =
'IMPLICIT_NULL'
NON_NULL =
'NON_NULL'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instrumentor = DummyInstrumentor.new) ⇒ Extractor

Returns a new instance of Extractor.



25
26
27
# File 'lib/graphql_metrics/extractor.rb', line 25

def initialize(instrumentor = DummyInstrumentor.new)
  @instrumentor = instrumentor
end

Instance Attribute Details

#queryObject (readonly)

Returns the value of attribute query.



23
24
25
# File 'lib/graphql_metrics/extractor.rb', line 23

def query
  @query
end

Instance Method Details

#extract!(query) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/graphql_metrics/extractor.rb', line 33

def extract!(query)
  @query = query

  return unless query.valid?
  return unless query.irep_selection

  extract_query

  used_variables = extract_used_variables

  query.operations.each_value do |operation|
    extract_variables(operation, used_variables)
  end

  extract_node(query.irep_selection)
  extract_batch_loaders
end

#extractor_defines_any_visitors?Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
59
60
# File 'lib/graphql_metrics/extractor.rb', line 51

def extractor_defines_any_visitors?
  [self, instrumentor].any? do |extractor_definer|
    extractor_definer.respond_to?(:query_extracted) ||
    extractor_definer.respond_to?(:field_extracted) ||
    extractor_definer.respond_to?(:argument_extracted) ||
    extractor_definer.respond_to?(:variable_extracted) ||
    extractor_definer.respond_to?(:batch_loaded_field_extracted) ||
    extractor_definer.respond_to?(:before_query_extracted)
  end
end

#handle_extraction_exception(ex) ⇒ Object



62
63
64
# File 'lib/graphql_metrics/extractor.rb', line 62

def handle_extraction_exception(ex)
  raise ex
end

#instrumentorObject



29
30
31
# File 'lib/graphql_metrics/extractor.rb', line 29

def instrumentor
  @instrumentor ||= DummyInstrumentor.new
end