Sha256: c9ea05dc25cbd37565ae7ad6212bf64b279328a8f5d889819fa2004e74b93901
Contents?: true
Size: 1.82 KB
Versions: 4
Compression:
Stored size: 1.82 KB
Contents
# frozen_string_literal: true require 'rails/generators/base' module Ibrain module Graphql module Core def self.included(base) base.send( :class_option, :directory, type: :string, default: "app/graphql", desc: "Directory where generated files should be saved" ) end def insert_root_type(type, name) log :add_root_type, type sentinel = /< GraphQL::Schema\s*\n/m in_root do if File.exist?(schema_file_path) inject_into_file schema_file_path, " #{type}(Types::#{name})\n", after: sentinel, verbose: false, force: false end end end def create_mutation_root_type create_dir("#{options[:directory]}/mutations") insert_root_type('mutation', 'MutationType') end def create_resolver_root_type create_dir("#{options[:directory]}/resolvers") insert_root_type('query', 'QueryType') end def schema_file_path "#{options[:directory]}/#{schema_name.underscore}.rb" end def create_dir(dir) empty_directory(dir) if !options[:skip_keeps] create_file("#{dir}/.keep") end end def module_namespacing_when_supported(&block) if defined?(module_namespacing) module_namespacing(&block) else yield end end private def schema_name @schema_name ||= options[:schema] || "#{parent_name}Schema" end def parent_name require File.expand_path("config/application", destination_root) if Rails.application.class.respond_to?(:module_parent_name) Rails.application.class.module_parent_name else Rails.application.class.parent_name end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems