Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use trace_with to start and end batches #164

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/graphql/batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ def self.batch(executor_class: GraphQL::Batch::Executor)
end

def self.use(schema_defn, executor_class: GraphQL::Batch::Executor)
instrumentation = GraphQL::Batch::SetupMultiplex.new(schema_defn, executor_class: executor_class)
schema_defn.instrument(:multiplex, instrumentation)
if schema_defn.respond_to?(:trace_with)
schema_defn.trace_with(GraphQL::Batch::SetupMultiplex::Trace, executor_class: executor_class)
else
instrumentation = GraphQL::Batch::SetupMultiplex.new(schema_defn, executor_class: executor_class)
schema_defn.instrument(:multiplex, instrumentation)
end

if schema_defn.mutation
require_relative "batch/mutation_field_extension"
Expand Down
14 changes: 14 additions & 0 deletions lib/graphql/batch/setup_multiplex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,19 @@ def before_multiplex(multiplex)
def after_multiplex(multiplex)
GraphQL::Batch::Executor.end_batch
end

module Trace
def initialize(executor_class:, **_rest)
@executor_class = executor_class
super
end

def execute_multiplex(multiplex:)
GraphQL::Batch::Executor.start_batch(@executor_class)
super
ensure
GraphQL::Batch::Executor.end_batch
end
end
end
end
Loading