Module: GraphqlRails::Attributes::Attributable

Included in:
Attribute, InputAttribute
Defined in:
lib/graphql_rails/attributes/attributable.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#field_nameObject



17
18
19
# File 'lib/graphql_rails/attributes/attributable.rb', line 17

def field_name
  attribute_name_parser.field_name
end

#graphql_modelObject



37
38
39
# File 'lib/graphql_rails/attributes/attributable.rb', line 37

def graphql_model
  type_parser.graphql_model
end

#initialize_copy(_original) ⇒ Object



11
12
13
14
15
# File 'lib/graphql_rails/attributes/attributable.rb', line 11

def initialize_copy(_original)
  super
  @attribute_name_parser = nil
  @type_parser = nil
end

#nameObject



25
26
27
# File 'lib/graphql_rails/attributes/attributable.rb', line 25

def name
  attribute_name_parser.name
end

#optional?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/graphql_rails/attributes/attributable.rb', line 41

def optional?
  !required?
end

#required?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
# File 'lib/graphql_rails/attributes/attributable.rb', line 29

def required?
  return @required unless @required.nil?

  (type.nil? && attribute_name_parser.required?) ||
    type.to_s[/!$/].present? ||
    type.is_a?(GraphQL::Schema::NonNull)
end

#scalar_type?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/graphql_rails/attributes/attributable.rb', line 45

def scalar_type?
  type_parser.raw_graphql_type? || type_parser.core_scalar_type?
end

#type_nameObject



21
22
23
# File 'lib/graphql_rails/attributes/attributable.rb', line 21

def type_name
  type.to_s
end