module GraphQL::Current
This module exposes Fiber-level runtime information.
It wonโt work across unrelated fibers, although it will work in child Fibers.
Examples
Example: Setting Up ActiveRecord::QueryLogs
config.active_record.query_log_tags = [ :namespaced_controller, :action, :job, # ... { # GraphQL runtime info: current_graphql_operation: -> { GraphQL::Current.operation_name }, current_graphql_field: -> { GraphQL::Current.field&.path }, current_dataloader_source: -> { GraphQL::Current.dataloader_source_class }, # ... }, ]
Public Class Methods
# File lib/graphql/current.rb, line 84 def self.dataloader_source Fiber[:__graphql_current_dataloader_source] end
Returns
-
GraphQL::Dataloader::Source, nilโ The currently-running source, if there is one
# File lib/graphql/current.rb, line 74 def self.dataloader_source_class Fiber[:__graphql_current_dataloader_source]&.class end
Returns
-
Class, nilโ The currently-runningDataloader::Sourceclass, if there is one.
# File lib/graphql/current.rb, line 58 def self.field if (interpreter_info = Fiber[:__graphql_runtime_info]) interpreter_info.values&.first&.current_field elsif (field = Fiber[:__graphql_current_field]) field else nil end end
See Schema::Member::HasPath#path for a string identifying this field
Returns
-
GraphQL::Field, nilโ The currently-running field, if there is one.
# File lib/graphql/current.rb, line 35 def self.operation_name if (m = Fiber[:__graphql_current_multiplex]) m.context[:__graphql_current_operation_name] ||= begin names = m.queries.map { |q| q.selected_operation_name } if names.all?(&:nil?) nil else names.join(",") end end else nil end end
Returns
-
String, nilโ Comma-joined operation names for the currently-runningExecution::Multiplex.nilif all operations are anonymous.