From 87abcf816360e6fdb635cdc1c355bc24ef29a5cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janko=20Marohni=C4=87?= Date: Mon, 25 Mar 2024 10:35:00 +0100 Subject: [PATCH] Use `.trace_with` on graphql-ruby 2.3+ --- lib/batch_loader/graphql.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/batch_loader/graphql.rb b/lib/batch_loader/graphql.rb index 04c9e11..f8ae756 100644 --- a/lib/batch_loader/graphql.rb +++ b/lib/batch_loader/graphql.rb @@ -2,11 +2,20 @@ class BatchLoader class GraphQL + module Trace + def execute_field(**_data) + result = yield + result.respond_to?(:__sync) ? BatchLoader::GraphQL.wrap_with_warning(result) : result + end + end + def self.use(schema_definition) schema_definition.lazy_resolve(BatchLoader::GraphQL, :sync) # in cases when BatchLoader is being used instead of BatchLoader::GraphQL - if schema_definition.respond_to?(:interpreter?) && schema_definition.interpreter? + if schema_definition.respond_to?(:trace_with) + schema_definition.trace_with(Trace) + elsif schema_definition.respond_to?(:interpreter?) && schema_definition.interpreter? schema_definition.tracer(self) else schema_definition.instrument(:field, self)