class GraphqlRails::Model::Input

stores information about model input specific config, like attributes and types

Attributes

input_name_suffix[R]
model_class[R]

Public Class Methods

new(model_class, input_name_suffix) click to toggle source
# File lib/graphql_rails/model/input.rb, line 12
def initialize(model_class, input_name_suffix)
  @model_class = model_class
  @input_name_suffix = input_name_suffix
end

Public Instance Methods

attribute(attribute_name, type: nil, enum: nil, **attribute_options) click to toggle source
# File lib/graphql_rails/model/input.rb, line 28
def attribute(attribute_name, type: nil, enum: nil, **attribute_options)
  input_type = attribute_type(attribute_name, type: type, enum: enum, **attribute_options)

  attributes[attribute_name.to_s] = Attributes::InputAttribute.new(
    attribute_name, type: input_type, **attribute_options
  )
end
graphql_input_type() click to toggle source
# File lib/graphql_rails/model/input.rb, line 22
def graphql_input_type
  @graphql_input_type ||= BuildGraphqlInputType.call(
    name: name, description: description, attributes: attributes
  )
end
initialize_copy(other) click to toggle source
Calls superclass method
# File lib/graphql_rails/model/input.rb, line 17
def initialize_copy(other)
  super
  @attributes = other.instance_variable_get(:@attributes)&.transform_values(&:dup)
end

Private Instance Methods

attribute_type(attribute_name, type:, enum:, description: nil, **_other) click to toggle source
# File lib/graphql_rails/model/input.rb, line 47
def attribute_type(attribute_name, type:, enum:, description: nil, **_other)
  return type unless enum

  BuildEnumType.call(
    "#{name}_#{attribute_name}_enum",
    allowed_values: enum,
    description: description
  )
end
default_name() click to toggle source
# File lib/graphql_rails/model/input.rb, line 40
def default_name
  @default_name ||= begin
    suffix = input_name_suffix ? input_name_suffix.to_s.camelize : ''
    "#{model_class.name.split('::').last}#{suffix}Input"
  end
end