Class: GraphqlRails::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql_rails/controller.rb,
lib/graphql_rails/controller/action.rb,
lib/graphql_rails/controller/request.rb,
lib/graphql_rails/controller/action_hook.rb,
lib/graphql_rails/controller/configuration.rb,
lib/graphql_rails/controller/action_hooks_runner.rb,
lib/graphql_rails/controller/action_configuration.rb,
lib/graphql_rails/controller/log_controller_action.rb,
lib/graphql_rails/controller/request/format_errors.rb,
lib/graphql_rails/controller/handle_controller_error.rb,
lib/graphql_rails/controller/build_controller_action_resolver.rb,
lib/graphql_rails/controller/build_controller_action_resolver/controller_action_resolver.rb

Overview

base class for all graphql_rails controllers

Defined Under Namespace

Classes: Action, ActionConfiguration, ActionHook, ActionHooksRunner, BuildControllerActionResolver, Configuration, HandleControllerError, LogControllerAction, Request

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(graphql_request) ⇒ Controller

Returns a new instance of Controller.



59
60
61
# File 'lib/graphql_rails/controller.rb', line 59

def initialize(graphql_request)
  @graphql_request = graphql_request
end

Instance Attribute Details

#action_nameObject (readonly)

Returns the value of attribute action_name.



57
58
59
# File 'lib/graphql_rails/controller.rb', line 57

def action_name
  @action_name
end

Class Method Details

.action(action_name) ⇒ Object



34
35
36
# File 'lib/graphql_rails/controller.rb', line 34

def action(action_name)
  controller_configuration.action(action_name)
end

.action_defaultObject



38
39
40
# File 'lib/graphql_rails/controller.rb', line 38

def action_default
  controller_configuration.action_default
end

.after_action(*args, **kwargs, &block) ⇒ Object



30
31
32
# File 'lib/graphql_rails/controller.rb', line 30

def after_action(*args, **kwargs, &block)
  controller_configuration.add_action_hook(:after, *args, **kwargs, &block)
end

.around_action(*args, **kwargs, &block) ⇒ Object



26
27
28
# File 'lib/graphql_rails/controller.rb', line 26

def around_action(*args, **kwargs, &block)
  controller_configuration.add_action_hook(:around, *args, **kwargs, &block)
end

.before_action(*args, **kwargs, &block) ⇒ Object



22
23
24
# File 'lib/graphql_rails/controller.rb', line 22

def before_action(*args, **kwargs, &block)
  controller_configuration.add_action_hook(:before, *args, **kwargs, &block)
end

.controller_configurationObject



46
47
48
# File 'lib/graphql_rails/controller.rb', line 46

def controller_configuration
  @controller_configuration ||= Controller::Configuration.new(self)
end

.inherited(subclass) ⇒ Object



16
17
18
19
20
# File 'lib/graphql_rails/controller.rb', line 16

def inherited(subclass)
  super
  new_config = controller_configuration.dup_with(controller: subclass)
  subclass.instance_variable_set(:@controller_configuration, new_config)
end

.model(*args) ⇒ Object



42
43
44
# File 'lib/graphql_rails/controller.rb', line 42

def model(*args)
  controller_configuration.model(*args)
end

.rescue_from(*errors, with: nil, &block) ⇒ Object



50
51
52
53
54
# File 'lib/graphql_rails/controller.rb', line 50

def rescue_from(*errors, with: nil, &block)
  Array(errors).each do |error|
    controller_configuration.add_error_handler(error, with: with, &block)
  end
end

Instance Method Details

#call(method_name) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/graphql_rails/controller.rb', line 63

def call(method_name)
  @action_name = method_name
  with_controller_action_logging do
    call_with_rendering
    graphql_request.object_to_return
  end
ensure
  @action_name = nil
end