Module: GraphqlRails::InputConfigurable

Included in:
Attributes::Attribute, Controller::ActionConfiguration
Defined in:
lib/graphql_rails/input_configurable.rb

Overview

contains configuration options related with inputs

Instance Method Summary collapse

Instance Method Details

#build_input_attribute(name, options: {}, **other_options) ⇒ Object



44
45
46
47
# File 'lib/graphql_rails/input_configurable.rb', line 44

def build_input_attribute(name, options: {}, **other_options)
  input_options = input_attribute_options.merge(options)
  Attributes::InputAttribute.new(name.to_s, config: self).with(options: input_options, **other_options)
end

#input_attribute_optionsObject



40
41
42
# File 'lib/graphql_rails/input_configurable.rb', line 40

def input_attribute_options
  @input_attribute_options || {}
end

#paginated(pagination_options = {}) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/graphql_rails/input_configurable.rb', line 24

def paginated(pagination_options = {})
  pagination_options = {} if pagination_options == true
  pagination_options = nil if pagination_options == false

  @pagination_options = pagination_options
  self
end

#paginated?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/graphql_rails/input_configurable.rb', line 32

def paginated?
  !pagination_options.nil?
end

#pagination_optionsObject



36
37
38
# File 'lib/graphql_rails/input_configurable.rb', line 36

def pagination_options
  @pagination_options
end

#permit(*args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/graphql_rails/input_configurable.rb', line 6

def permit(*args)
  args.each do |arg|
    if arg.is_a? Hash
      arg.each { |attribute, type| permit_input(attribute, type: type) }
    else
      permit_input(arg)
    end
  end
  self
end

#permit_input(name, **input_options) ⇒ Object



17
18
19
20
21
22
# File 'lib/graphql_rails/input_configurable.rb', line 17

def permit_input(name, **input_options)
  field_name = name.to_s.remove(/!\Z/)

  attributes[field_name] = build_input_attribute(name.to_s, **input_options)
  self
end