class GraphqlRails::Model::Configuration

stores information about model specific config, like attributes and types

Attributes

model_class[R]

Public Class Methods

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

Public Instance Methods

attribute(attribute_name, **attribute_options) { |attribute| ... } click to toggle source
# File lib/graphql_rails/model/configuration.rb, line 28
def attribute(attribute_name, **attribute_options)
  key = attribute_name.to_s

  attributes[key] ||= Attributes::Attribute.new(attribute_name)

  attributes[key].tap do |attribute|
    attribute_options.each do |method_name, args|
      send_args = [method_name]
      send_args << args if attribute.method(method_name).parameters.present?
      attribute.public_send(*send_args)
    end

    yield(attribute) if block_given?
  end
end
connection_type() click to toggle source
# File lib/graphql_rails/model/configuration.rb, line 67
def connection_type
  @connection_type ||= BuildConnectionType.call(graphql_type)
end
graphql_type() click to toggle source
# File lib/graphql_rails/model/configuration.rb, line 58
def graphql_type
  @graphql_type ||= FindOrBuildGraphqlType.call(
    name: name,
    description: description,
    attributes: attributes,
    type_name: type_name
  )
end
initialize_copy(other) click to toggle source
Calls superclass method
# File lib/graphql_rails/model/configuration.rb, line 20
def initialize_copy(other)
  super
  @connection_type = nil
  @graphql_type = nil
  @input = other.instance_variable_get(:@input)&.transform_values(&:dup)
  @attributes = other.instance_variable_get(:@attributes)&.transform_values(&:dup)
end
input(input_name = nil) { |input| ... } click to toggle source
# File lib/graphql_rails/model/configuration.rb, line 44
def input(input_name = nil)
  @input ||= {}
  name = input_name.to_s

  if block_given?
    @input[name] ||= Model::Input.new(model_class, input_name)
    yield(@input[name])
  end

  @input.fetch(name) do
    raise("GraphQL input with name #{input_name.inspect} is not defined for #{model_class.name}")
  end
end
with_ensured_fields!() click to toggle source
# File lib/graphql_rails/model/configuration.rb, line 71
def with_ensured_fields!
  return self if @graphql_type.blank?

  reset_graphql_type if attributes.any? && graphql_type.fields.length != attributes.length

  self
end

Private Instance Methods

default_name() click to toggle source
# File lib/graphql_rails/model/configuration.rb, line 83
def default_name
  @default_name ||= model_class.name.split('::').last
end
reset_graphql_type() click to toggle source
# File lib/graphql_rails/model/configuration.rb, line 87
def reset_graphql_type
  @graphql_type = FindOrBuildGraphqlType.call(
    name: name,
    description: description,
    attributes: attributes,
    type_name: type_name,
    force_define_attributes: true
  )
end