Module: Graphql::Generators::Core

Included in:
InstallGenerator, LoaderGenerator, MutationGenerator, RelayGenerator, TypeGeneratorBase
Defined in:
lib/generators/graphql/core.rb

Instance Method Summary collapse

Instance Method Details

#create_dir(dir) ⇒ Object



37
38
39
40
41
42
# File 'lib/generators/graphql/core.rb', line 37

def create_dir(dir)
  empty_directory(dir)
  if !options[:skip_keeps]
    create_file("#{dir}/.keep")
  end
end

#create_mutation_root_typeObject



26
27
28
29
30
31
# File 'lib/generators/graphql/core.rb', line 26

def create_mutation_root_type
  create_dir("#{options[:directory]}/mutations")
  template("base_mutation.erb", "#{options[:directory]}/mutations/base_mutation.rb", { skip: true })
  template("mutation_type.erb", "#{options[:directory]}/types/mutation_type.rb", { skip: true })
  insert_root_type('mutation', 'MutationType')
end

#insert_root_type(type, name) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/generators/graphql/core.rb', line 17

def insert_root_type(type, name)
  log :add_root_type, type
  sentinel = /< GraphQL::Schema\s*\n/m

  in_root do
    inject_into_file schema_file_path, "  #{type}(Types::#{name})\n", after: sentinel, verbose: false, force: false
  end
end

#module_namespacing_when_supportedObject



44
45
46
47
48
49
50
# File 'lib/generators/graphql/core.rb', line 44

def module_namespacing_when_supported
  if defined?(module_namespacing)
    module_namespacing { yield }
  else
    yield
  end
end

#schema_file_pathObject



33
34
35
# File 'lib/generators/graphql/core.rb', line 33

def schema_file_path
  "#{options[:directory]}/#{schema_name.underscore}.rb"
end