Module: Rails::GraphQL::Helpers::WithName

Defined in:
lib/rails/graphql/helpers/with_name.rb

Overview

Helper module responsible for name stuff

Constant Summary collapse

NAME_EXP =
/GraphQL::(?:Type::\w+::|Directive::)?([:\w]+)\z/.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(other) ⇒ Object

Here we define a couple of attributes used by registration



13
14
15
16
17
18
# File 'lib/rails/graphql/helpers/with_name.rb', line 13

def self.extended(other)
  # TODO: Move to registerable
  # An abstract type won't appear in the introspection and will not be
  # instantiated by requests
  other.class_attribute :abstract, instance_accessor: false, default: false
end

Instance Method Details

#gql_nameObject Also known as: graphql_name

Return the name of the object as a GraphQL name



21
22
23
24
25
26
# File 'lib/rails/graphql/helpers/with_name.rb', line 21

def gql_name
  @gql_name ||= begin
    result = name.match(NAME_EXP).try(:[], 1)
    result.tr(':', '').chomp(base_type.name.demodulize) unless result.nil?
  end unless anonymous?
end

#to_symObject

Return the name of the object as a symbol



31
32
33
# File 'lib/rails/graphql/helpers/with_name.rb', line 31

def to_sym
  @gql_key ||= gql_name&.underscore&.to_sym
end