Sha256: d2efc871f73be2e7b1450c2076e0c02d3e86871d648616063ceaca5a619490f8

Contents?: true

Size: 1.18 KB

Versions: 9

Compression:

Stored size: 1.18 KB

Contents

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

module Graphql
  module Generators
    module Core
      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("app/graphql/mutations")
        template("mutation_type.erb", "app/graphql/types/mutation_type.rb", { skip: true })
        insert_root_type('mutation', 'MutationType')
      end

      def schema_file_path
        "app/graphql/#{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

9 entries across 9 versions & 1 rubygems

Version Path
graphql-1.7.4 lib/generators/graphql/core.rb
graphql-1.7.3 lib/generators/graphql/core.rb
graphql-1.7.2 lib/generators/graphql/core.rb
graphql-1.7.1 lib/generators/graphql/core.rb
graphql-1.7.0 lib/generators/graphql/core.rb
graphql-1.6.8 lib/generators/graphql/core.rb
graphql-1.6.7 lib/generators/graphql/core.rb
graphql-1.6.6 lib/generators/graphql/core.rb
graphql-1.6.5 lib/generators/graphql/core.rb