Class: GraphqlRails::Controller::ActionConfiguration

Inherits:
Object
  • Object
show all
Includes:
InputConfigurable
Defined in:
lib/graphql_rails/controller/action_configuration.rb

Overview

stores all graphql_rails controller specific config

Defined Under Namespace

Classes: DeprecatedDefaultModelError, MissingConfigurationError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from InputConfigurable

#build_input_attribute, #input_attribute_options, #paginated?, #permit, #permit_input

Constructor Details

#initialize(name:, controller:) ⇒ ActionConfiguration

Returns a new instance of ActionConfiguration.



26
27
28
29
30
31
# File 'lib/graphql_rails/controller/action_configuration.rb', line 26

def initialize(name:, controller:)
  @name = name
  @controller = controller
  @attributes = {}
  @action_options = {}
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



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

def attributes
  @attributes
end

#controllerObject (readonly)

Returns the value of attribute controller.



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

def controller
  @controller
end

#defined_atObject (readonly)

Returns the value of attribute defined_at.



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

def defined_at
  @defined_at
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#pagination_optionsObject (readonly)

Returns the value of attribute pagination_options.



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

def pagination_options
  @pagination_options
end

Instance Method Details

#description(new_description = nil) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/graphql_rails/controller/action_configuration.rb', line 55

def description(new_description = nil)
  if new_description
    @description = new_description
    self
  else
    @description
  end
end

#dup_with(name:, controller:, defined_at:) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/graphql_rails/controller/action_configuration.rb', line 33

def dup_with(name:, controller:, defined_at:)
  dup.tap do |new_action|
    new_action.instance_variable_set(:@defined_at, defined_at)
    new_action.instance_variable_set(:@name, name)
    new_action.instance_variable_set(:@controller, controller)
  end
end

#initialize_copy(other) ⇒ Object



19
20
21
22
23
24
# File 'lib/graphql_rails/controller/action_configuration.rb', line 19

def initialize_copy(other)
  super
  @attributes = other.instance_variable_get(:@attributes).dup.transform_values(&:dup)
  @action_options = other.instance_variable_get(:@action_options).dup.transform_values(&:dup)
  @pagination_options = other.instance_variable_get(:@pagination_options)&.dup&.transform_values(&:dup)
end

#model(model_name = nil) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/graphql_rails/controller/action_configuration.rb', line 70

def model(model_name = nil)
  if model_name
    @model = model_name
    self
  else
    @model || raise_missing_config_error
  end
end

#options(action_options = nil) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/graphql_rails/controller/action_configuration.rb', line 41

def options(action_options = nil)
  @input_attribute_options ||= {}
  return @input_attribute_options if action_options.nil?

  @input_attribute_options[:input_format] = action_options[:input_format] if action_options[:input_format]

  self
end

#paginated(*args) ⇒ Object



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

def paginated(*args)
  @return_type = nil
  super
end

#return_typeObject



95
96
97
# File 'lib/graphql_rails/controller/action_configuration.rb', line 95

def return_type
  @return_type ||= build_return_type
end

#returns(custom_return_type) ⇒ Object



64
65
66
67
68
# File 'lib/graphql_rails/controller/action_configuration.rb', line 64

def returns(custom_return_type)
  @return_type = nil
  @custom_return_type = custom_return_type
  self
end

#returns_list(required_inner: true, required_list: true) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/graphql_rails/controller/action_configuration.rb', line 86

def returns_list(required_inner: true, required_list: true)
  model_name = model.to_s
  model_name = "#{model_name}!" if required_inner
  list_name = "[#{model_name}]"
  list_name = "#{list_name}!" if required_list

  returns(list_name)
end

#returns_single(required: true) ⇒ Object



79
80
81
82
83
84
# File 'lib/graphql_rails/controller/action_configuration.rb', line 79

def returns_single(required: true)
  model_name = model.to_s
  model_name = "#{model_name}!" if required

  returns(model_name)
end

#type_parserObject



99
100
101
# File 'lib/graphql_rails/controller/action_configuration.rb', line 99

def type_parser
  @type_parser ||= Attributes::TypeParser.new(custom_return_type, paginated: paginated?)
end