Overview
TheCallback class is a central component of the Rails GraphQL event system. It wraps blocks or symbols as callbacks that can be triggered by events, with support for filtering, argument injection, and context management.
Class Methods
set_context
Contextualizes a callback with a given instance.The callback proc to contextualize
The context instance to bind to the callback
Returns a lambda that injects the context as
_callback_contextInstance Methods
initialize
Creates a new callback instance.The target object that owns this callback
The name of the event this callback responds to
Optional arguments to prepend when calling the callback
Keyword arguments including filters and options. Special option
exclusive_callback controls exclusivity.The callback block or a symbol representing a method name
call
Executes the callback if the event matches and filters pass.The event being triggered
Arguments to pass to the callback
Optional context for the callback execution
Keyword arguments to pass to the callback
The result of the callback execution, or nil if the callback doesn’t run
exclusive?
Checks if the callback is exclusive to its source.Returns true if only the original source can trigger this callback
source_location
Returns the source location of the callback for debugging.Returns [file_path, line_number] for proc callbacks, or a descriptive array for symbol callbacks
to_proc
Converts the callback to a proc.Returns a proc that can be used with the
& operatorAttributes
The name of the event this callback responds to
The callback implementation (proc or method symbol)
The object that owns this callback
The filters that determine when this callback can run
Constants
The keyword argument key used to control exclusivity:
:exclusive_callbackArgument Injection
Callbacks support automatic argument injection based on configuration:- Named arguments: When
callback_inject_named_argumentsis enabled, keyword parameters are automatically injected from the event data - Positional arguments: When
callback_inject_argumentsis enabled, positional parameters are injected by name from the event
Filters
Callbacks can be filtered using event filters. All filters must pass for the callback to execute. Filters are evaluated usinginstance_exec on the target with the filter options and event.