Class: GraphQL::Tracing::PlatformTracing Private

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/tracing/platform_tracing.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Each platform provides:

  • .platform_keys
  • #platform_trace
  • #platform_field_key(type, field)

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePlatformTracing

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of PlatformTracing.



15
16
17
# File 'lib/graphql/tracing/platform_tracing.rb', line 15

def initialize
  @platform_keys = self.class.platform_keys
end

Class Attribute Details

.platform_keysObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



12
13
14
# File 'lib/graphql/tracing/platform_tracing.rb', line 12

def platform_keys
  @platform_keys
end

Class Method Details

.use(schema_defn) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



52
53
54
55
56
# File 'lib/graphql/tracing/platform_tracing.rb', line 52

def self.use(schema_defn)
  tracer = self.new
  schema_defn.instrument(:field, tracer)
  schema_defn.tracer(tracer)
end

Instance Method Details

#instrument(type, field) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/graphql/tracing/platform_tracing.rb', line 40

def instrument(type, field)
  return_type = field.type.unwrap
  case return_type
  when GraphQL::ScalarType, GraphQL::EnumType
    field
  else
    new_f = field.redefine
    new_f.[:platform_key] = platform_field_key(type, field)
    new_f
  end
end

#trace(key, data) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/graphql/tracing/platform_tracing.rb', line 19

def trace(key, data)
  case key
  when "lex", "parse", "validate", "analyze_query", "analyze_multiplex", "execute_query", "execute_query_lazy", "execute_multiplex"
    platform_key = @platform_keys.fetch(key)
    platform_trace(platform_key, key, data) do
      yield
    end
  when "execute_field", "execute_field_lazy"
    if (platform_key = data[:context].field.[:platform_key])
      platform_trace(platform_key, key, data) do
        yield
      end
    else
      yield
    end
  else
    # it's a custom key
    yield
  end
end