lib/graphql/tracing/platform_tracing.rb in graphql-1.13.23 vs lib/graphql/tracing/platform_tracing.rb in graphql-2.0.0

- old
+ new

@@ -8,14 +8,10 @@ # - `#platform_field_key(type, field)` # @api private class PlatformTracing class << self attr_accessor :platform_keys - - def inherited(child_class) - child_class.platform_keys = self.platform_keys - end end def initialize(options = {}) @options = options @platform_keys = self.class.platform_keys @@ -34,21 +30,20 @@ field = data[:context].field platform_key = field.metadata[:platform_key] trace_field = true # implemented with instrumenter else field = data[:field] - # HERE 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 context = data.fetch(:query).context - cached_platform_key(context, field, :field) { platform_field_key(data[:owner], field) } + cached_platform_key(context, field) { platform_field_key(data[:owner], field) } else nil end end @@ -60,52 +55,29 @@ yield end when "authorized", "authorized_lazy" type = data.fetch(:type) context = data.fetch(:context) - platform_key = cached_platform_key(context, type, :authorized) { platform_authorized_key(type) } + platform_key = cached_platform_key(context, type) { platform_authorized_key(type) } platform_trace(platform_key, key, data) do yield end when "resolve_type", "resolve_type_lazy" type = data.fetch(:type) context = data.fetch(:context) - platform_key = cached_platform_key(context, type, :resolve_type) { platform_resolve_type_key(type) } + platform_key = cached_platform_key(context, type) { platform_resolve_type_key(type) } platform_trace(platform_key, key, data) do yield end else # it's a custom key yield end end - def instrument(type, field) - return_type = field.type.unwrap - case return_type - when GraphQL::ScalarType, GraphQL::EnumType - if field.trace || (field.trace.nil? && @trace_scalars) - trace_field(type, field) - else - field - end - else - trace_field(type, field) - end - end - - def trace_field(type, field) - new_f = field.redefine - new_f.metadata[:platform_key] = platform_field_key(type, field) - new_f - end - def self.use(schema_defn, options = {}) tracer = self.new(**options) - if !schema_defn.is_a?(Class) - schema_defn.instrument(:field, tracer) - end schema_defn.tracer(tracer) end private @@ -138,10 +110,10 @@ # So, they can all share one cache. # # If the key isn't present, the given block is called and the result is cached for `key`. # # @return [String] - def cached_platform_key(ctx, key, trace_phase) + def cached_platform_key(ctx, key) cache = ctx.namespace(self.class)[:platform_key_cache] ||= {} cache.fetch(key) { cache[key] = yield } end end end