Module: Graphiti::Rails::Context

Defined in:
lib/graphiti/rails/context.rb

Overview

Wraps controller actions in a [Graphiti Context](www.graphiti.dev/guides/concepts/resources#context) which points to the controller instance by default.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



6
7
8
9
10
11
# File 'lib/graphiti/rails/context.rb', line 6

def self.included(klass)
  klass.class_eval do
    include Graphiti::Context
    around_action :wrap_graphiti_context
  end
end

Instance Method Details

#graphiti_contextObject

The context to use for Graphiti Resources. Defaults to the controller instance. Can be redefined for different behavior.



23
24
25
26
27
28
29
30
# File 'lib/graphiti/rails/context.rb', line 23

def graphiti_context
  if respond_to?(:jsonapi_context)
    DEPRECATOR.deprecation_warning("Overriding jsonapi_context", "Override #graphiti_context instead")
    jsonapi_context
  else
    self
  end
end

#wrap_graphiti_contextObject

Called by [‘#around_action`](api.rubyonrails.org/classes/AbstractController/Callbacks/ClassMethods.html#method-i-around_action) to wrap the current action in a Graphiti context defined by #graphiti_context.



15
16
17
18
19
# File 'lib/graphiti/rails/context.rb', line 15

def wrap_graphiti_context
  Graphiti.with_context(graphiti_context, action_name.to_sym) do
    yield
  end
end