Module: GraphQL::Tracing::PlatformTrace

Included in:
AppOpticsTrace
Defined in:
lib/graphql/tracing/platform_trace.rb

Defined Under Namespace

Modules: BaseKeyCache

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(child_class) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/graphql/tracing/platform_trace.rb', line 39

def self.included(child_class)
  key_methods_class = Class.new {
    include(child_class)
    include(BaseKeyCache)
  }
  child_class.const_set(:KeyCache, key_methods_class)

  # rubocop:disable Development/NoEvalCop This eval takes static inputs at load-time

  [:execute_field, :execute_field_lazy].each do |field_trace_method|
    if !child_class.method_defined?(field_trace_method)
      child_class.module_eval <<-RUBY, __FILE__, __LINE__
        def #{field_trace_method}(query:, field:, ast_node:, arguments:, object:)
          return_type = field.type.unwrap
          trace_field = if return_type.kind.scalar? || return_type.kind.enum?
            (field.trace.nil? && @trace_scalars) || field.trace
          else
            true
          end
          platform_key = if trace_field
            @platform_key_cache[#{child_class}].platform_field_key_cache[field]
          else
            nil
          end
          if platform_key && trace_field
            platform_#{field_trace_method}(platform_key) do
              super
            end
          else
            super
          end
        end
      RUBY
    end
  end


  [:authorized, :authorized_lazy].each do |auth_trace_method|
    if !child_class.method_defined?(auth_trace_method)
      child_class.module_eval <<-RUBY, __FILE__, __LINE__
        def #{auth_trace_method}(type:, query:, object:)
          platform_key = @platform_key_cache[#{child_class}].platform_authorized_key_cache[type]
          platform_#{auth_trace_method}(platform_key) do
            super
          end
        end
      RUBY
    end
  end

  [:resolve_type, :resolve_type_lazy].each do |rt_trace_method|
    if !child_class.method_defined?(rt_trace_method)
      child_class.module_eval <<-RUBY, __FILE__, __LINE__
        def #{rt_trace_method}(query:, type:, object:)
          platform_key = @platform_key_cache[#{child_class}].platform_resolve_type_key_cache[type]
          platform_#{rt_trace_method}(platform_key) do
            super
          end
        end
      RUBY
    end

    # rubocop:enable Development/NoEvalCop
  end
end

Instance Method Details

#initialize(trace_scalars: false, **_options) ⇒ Object



8
9
10
11
12
13
# File 'lib/graphql/tracing/platform_trace.rb', line 8

def initialize(trace_scalars: false, **_options)
  @trace_scalars = trace_scalars

  @platform_key_cache = Hash.new { |h, mod| h[mod] = mod.const_get(:KeyCache).new }
  super
end

#platform_authorized_lazy(key, &block) ⇒ Object



31
32
33
# File 'lib/graphql/tracing/platform_trace.rb', line 31

def platform_authorized_lazy(key, &block)
  platform_authorized(key, &block)
end

#platform_execute_field_lazy(*args, &block) ⇒ Object



26
27
28
29
# File 'lib/graphql/tracing/platform_trace.rb', line 26

def platform_execute_field_lazy(*args, &block)
  args = args #: untyped
  platform_execute_field(*args, &block)
end

#platform_resolve_type_lazy(key, &block) ⇒ Object



35
36
37
# File 'lib/graphql/tracing/platform_trace.rb', line 35

def platform_resolve_type_lazy(key, &block)
  platform_resolve_type(key, &block)
end