Module: GraphQL::Current
- Defined in:
- lib/graphql/current.rb
Overview
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. = [
: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 },
# ...
},
]
Class Method Summary collapse
-
.dataloader_source ⇒ Object
Returns.
-
.dataloader_source_class ⇒ Object
Returns.
-
.field ⇒ Object
See Schema::Member::HasPath#path for a string identifying this field.
-
.operation_name ⇒ Object
Returns.
Class Method Details
.dataloader_source ⇒ Object
Returns
GraphQL::Dataloader::Source, nil— The currently-running source, if there is one
:call-seq:
dataloader_source() -> GraphQL::Dataloader::Source | nil
: () -> GraphQL::Dataloader::Source?
89 90 91 |
# File 'lib/graphql/current.rb', line 89 def self.dataloader_source Fiber[:__graphql_current_dataloader_source] end |
.dataloader_source_class ⇒ Object
Returns
Class, nil— The currently-running Dataloader::Source class, if there is one.
:call-seq:
dataloader_source_class() -> Class | nil
: () -> singleton(GraphQL::Dataloader::Source)?
78 79 80 |
# File 'lib/graphql/current.rb', line 78 def self.dataloader_source_class Fiber[:__graphql_current_dataloader_source]&.class end |
.field ⇒ Object
See Schema::Member::HasPath#path for a string identifying this field
Returns
GraphQL::Field, nil— The currently-running field, if there is one.
:call-seq:
field() -> GraphQL::Field | nil
: () -> GraphQL::Schema::Field?
61 62 63 64 65 66 67 68 69 |
# File 'lib/graphql/current.rb', line 61 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 |
.operation_name ⇒ Object
Returns
String, nil— Comma-joined operation names for the currently-runningExecution::Multiplex.nilif all operations are anonymous.
:call-seq:
operation_name() -> String | nil
: () -> String?
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/graphql/current.rb', line 37 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 |