Class: Rails::GraphQL::Type::Creator

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/graphql/type/creator.rb

Overview

GraphQL Type Creator

This class helps to dynamically create types using a large set of settings that are provided through the named arguments. There are setting that are general to all types, and some are specific per base type of the superclass

Constant Summary collapse

NESTED_MODULE =
:NestedTypes
SUPPORTED_KINDS =
%i[scalar object interface union enum input_object source].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from, name_or_object, superclass, **settings) ⇒ Creator

Returns a new instance of Creator.



26
27
28
29
30
31
32
33
# File 'lib/rails/graphql/type/creator.rb', line 26

def initialize(from, name_or_object, superclass, **settings)
  @from = from
  @settings = settings
  @object = name_or_object if name_or_object.is_a?(Class)

  @superclass = sanitize_superclass(superclass)
  @name = sanitize_name(name_or_object)
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



16
17
18
# File 'lib/rails/graphql/type/creator.rb', line 16

def klass
  @klass
end

#nameObject (readonly)

Returns the value of attribute name.



16
17
18
# File 'lib/rails/graphql/type/creator.rb', line 16

def name
  @name
end

#settingsObject (readonly)

Returns the value of attribute settings.



16
17
18
# File 'lib/rails/graphql/type/creator.rb', line 16

def settings
  @settings
end

#superclassObject (readonly)

Returns the value of attribute superclass.



16
17
18
# File 'lib/rails/graphql/type/creator.rb', line 16

def superclass
  @superclass
end

Class Method Details

.create!(*args, **xargs, &block) ⇒ Object

Simply instantiate the creator and run the process



22
23
24
# File 'lib/rails/graphql/type/creator.rb', line 22

def self.create!(*args, **xargs, &block)
  new(*args, **xargs).create!(&block)
end

Instance Method Details

#create!(&block) ⇒ Object

Go over the create process



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rails/graphql/type/creator.rb', line 36

def create!(&block)
  @klass = find_or_create_class
  klass.instance_variable_set(:@gql_name, gql_name)

  apply_general_settings
  after_block = apply_specific_settings

  klass.module_exec(&block) if block.present?
  after_block.call if after_block.is_a?(Proc)
  klass
end