Sha256: 9e6d6a1f524d5bc42cb573653550c67f0b874bf8ceb9d2fa9df4e2708063b4be

Contents?: true

Size: 1.45 KB

Versions: 23

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true
require 'rails/generators/base'

module Graphql
  module Generators
    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\.define do\s*\n/m

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

      def create_mutation_root_type
        create_dir("#{options[:directory]}/mutations")
        template("mutation_type.erb", "#{options[:directory]}/types/mutation_type.rb", { skip: true })
        insert_root_type('mutation', 'MutationType')
      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

      private

      def schema_name
        @schema_name ||= begin
          if options[:schema]
            options[:schema]
          else
            require File.expand_path("config/application", destination_root)
            "#{Rails.application.class.parent_name}Schema"
          end
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
graphql-1.8.1 lib/generators/graphql/core.rb
graphql-1.8.0 lib/generators/graphql/core.rb
graphql-1.8.0.pre11 lib/generators/graphql/core.rb
graphql-1.8.0.pre10 lib/generators/graphql/core.rb
graphql-1.7.14 lib/generators/graphql/core.rb
graphql-1.8.0.pre9 lib/generators/graphql/core.rb
graphql-1.8.0.pre8 lib/generators/graphql/core.rb
graphql-1.7.13 lib/generators/graphql/core.rb
graphql-1.8.0.pre7 lib/generators/graphql/core.rb
graphql-1.7.12 lib/generators/graphql/core.rb
graphql-1.7.11 lib/generators/graphql/core.rb
graphql-1.7.10 lib/generators/graphql/core.rb
graphql-1.8.0.pre6 lib/generators/graphql/core.rb
graphql-1.8.0.pre5 lib/generators/graphql/core.rb
graphql-1.7.9 lib/generators/graphql/core.rb
graphql-1.8.0.pre4 lib/generators/graphql/core.rb
graphql-1.8.0.pre3 lib/generators/graphql/core.rb
graphql-1.7.8 lib/generators/graphql/core.rb
graphql-1.8.0.pre2 lib/generators/graphql/core.rb
graphql-1.7.7 lib/generators/graphql/core.rb