Class: Ibrain::Graphql::ResolverGenerator

Inherits:
ResolversGenerator show all
Defined in:
lib/generators/ibrain/graphql/resolver_generator.rb

Overview

TODO: What other options should be supported?

Examples:

Generate a ‘GraphQL::Schema::Resolver` by name

rails g graphql:resolver PostsResolver

Instance Attribute Summary

Attributes inherited from ResolversGenerator

#field_name, #file_name, #model_name, #resolver_name

Instance Method Summary collapse

Methods inherited from ResolversGenerator

#initialize

Methods included from Core

#create_dir, #create_mutation_root_type, #create_repository_root_type, #create_resolver_root_type, included, #insert_root_type, #module_namespacing_when_supported, #schema_file_path

Constructor Details

This class inherits a constructor from Ibrain::Graphql::ResolversGenerator

Instance Method Details

#create_resolver_fileObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/generators/ibrain/graphql/resolver_generator.rb', line 16

def create_resolver_file
  if @behavior == :revoke
    log :gsub, "#{options[:directory]}/types/query_type.rb"
  else
    create_resolver_root_type
  end

  if options[:model].present?
    system("bundle exec rails generate ibrain:graphql:object #{options[:model].underscore}")
  end

  template "resolver.erb", "#{options[:directory]}/resolvers/#{file_name}.rb"
  return unless ::Ibrain::Config.is_auto_append_mutation

  in_root do
    gsub_file "#{options[:directory]}/types/query_type.rb", /  \# TODO: Add Resolvers as fields\s*\n/m, ""
    inject_into_file "#{options[:directory]}/types/query_type.rb", "\n    field :#{field_name}, resolver: Resolvers::#{resolver_name} \n  ", before: "end\nend", verbose: true, force: true
  end
end