Sha256: e8156a5f2c16b9d3d68f225e6885f3db0729d702f0c58979ffa5af97f6c70ca4

Contents?: true

Size: 1.44 KB

Versions: 38

Compression:

Stored size: 1.44 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\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

38 entries across 38 versions & 1 rubygems

Version Path
graphql-1.8.18 lib/generators/graphql/core.rb
graphql-1.9.15 lib/generators/graphql/core.rb
graphql-1.9.14 lib/generators/graphql/core.rb
graphql-1.10.0.pre1 lib/generators/graphql/core.rb
graphql-1.9.13 lib/generators/graphql/core.rb
graphql-1.9.12 lib/generators/graphql/core.rb
graphql-1.9.11 lib/generators/graphql/core.rb
graphql-1.9.10 lib/generators/graphql/core.rb
graphql-1.9.9 lib/generators/graphql/core.rb
graphql-1.9.8 lib/generators/graphql/core.rb
graphql-1.9.7 lib/generators/graphql/core.rb
graphql-1.9.6 lib/generators/graphql/core.rb
graphql-1.9.5 lib/generators/graphql/core.rb
graphql-1.9.4 lib/generators/graphql/core.rb
graphql-1.9.3 lib/generators/graphql/core.rb
graphql-1.9.2 lib/generators/graphql/core.rb
graphql-1.8.17 lib/generators/graphql/core.rb
graphql-1.8.16 lib/generators/graphql/core.rb
graphql-1.9.1 lib/generators/graphql/core.rb
graphql-1.9.0 lib/generators/graphql/core.rb