lib/graphql/tracing/platform_tracing.rb in graphql-1.10.0.pre3 vs lib/graphql/tracing/platform_tracing.rb in graphql-1.10.0.pre4
- old
+ new
@@ -19,11 +19,10 @@
end
def trace(key, data)
case key
when "lex", "parse", "validate", "analyze_query", "analyze_multiplex", "execute_query", "execute_query_lazy", "execute_multiplex"
- data.fetch(:query).context.namespace(self.class)[:platform_key_cache] = {} if key == "execute_query"
platform_key = @platform_keys.fetch(key)
platform_trace(platform_key, key, data) do
yield
end
when "execute_field", "execute_field_lazy"
@@ -31,13 +30,13 @@
field = data[:context].field
platform_key = field.metadata[:platform_key]
trace_field = true # implemented with instrumenter
else
field = data[:field]
- platform_key_cache = data.fetch(:query).context.namespace(self.class).fetch(:platform_key_cache)
- platform_key = platform_key_cache.fetch(field) do
- platform_key_cache[field] = platform_field_key(data[:owner], field)
+ cache = platform_key_cache(data.fetch(:query).context)
+ platform_key = cache.fetch(field) do
+ cache[field] = platform_field_key(data[:owner], field)
end
return_type = field.type.unwrap
trace_field = if return_type.kind.scalar? || return_type.kind.enum?
(field.trace.nil? && @trace_scalars) || field.trace
@@ -51,10 +50,28 @@
yield
end
else
yield
end
+ when "authorized", "authorized_lazy"
+ cache = platform_key_cache(data.fetch(:context))
+ type = data.fetch(:type)
+ platform_key = cache.fetch(type) do
+ cache[type] = platform_authorized_key(type)
+ end
+ platform_trace(platform_key, key, data) do
+ yield
+ end
+ when "resolve_type", "resolve_type_lazy"
+ cache = platform_key_cache(data.fetch(:context))
+ type = data.fetch(:type)
+ platform_key = cache.fetch(type) do
+ cache[type] = platform_resolve_type_key(type)
+ end
+ platform_trace(platform_key, key, data) do
+ yield
+ end
else
# it's a custom key
yield
end
end
@@ -85,8 +102,12 @@
schema_defn.tracer(tracer)
end
private
attr_reader :options
+
+ def platform_key_cache(ctx)
+ ctx.namespace(self.class)[:platform_key_cache] ||= {}
+ end
end
end
end