module GraphqlRails::Attributes::Attributable

contains methods which are shared between various attribute-like classes expects `initial_name` and `initial_type` to be defined

Public Instance Methods

field_name() click to toggle source
# File lib/graphql_rails/attributes/attributable.rb, line 11
def field_name
  attribute_name_parser.field_name
end
graphql_model() click to toggle source
# File lib/graphql_rails/attributes/attributable.rb, line 39
def graphql_model
  type_parser.graphql_model
end
name() click to toggle source
# File lib/graphql_rails/attributes/attributable.rb, line 19
def name
  attribute_name_parser.name
end
optional() click to toggle source
# File lib/graphql_rails/attributes/attributable.rb, line 34
def optional
  @required = false
  self
end
optional?() click to toggle source
# File lib/graphql_rails/attributes/attributable.rb, line 43
def optional?
  !required?
end
required() click to toggle source
# File lib/graphql_rails/attributes/attributable.rb, line 29
def required
  @required = true
  self
end
required?() click to toggle source
# File lib/graphql_rails/attributes/attributable.rb, line 23
def required?
  return @required unless @required.nil?

  attribute_name_parser.required? || !initial_type.to_s[/!$/].nil? || initial_type.is_a?(GraphQL::Schema::NonNull)
end
scalar_type?() click to toggle source
# File lib/graphql_rails/attributes/attributable.rb, line 47
def scalar_type?
  type_parser.raw_graphql_type? || type_parser.core_scalar_type?
end
type_name() click to toggle source
# File lib/graphql_rails/attributes/attributable.rb, line 15
def type_name
  @type_name ||= initial_type.to_s
end

Private Instance Methods

attribute_name_parser() click to toggle source
# File lib/graphql_rails/attributes/attributable.rb, line 60
def attribute_name_parser
  @attribute_name_parser ||= AttributeNameParser.new(initial_name, options: options)
end
type_parser() click to toggle source
# File lib/graphql_rails/attributes/attributable.rb, line 53
def type_parser
  @type_parser ||= begin
    type_for_parser = initial_type || attribute_name_parser.graphql_type
    TypeParser.new(type_for_parser, paginated: paginated?)
  end
end