lib/generators/graphql/install_generator.rb in graphql-1.6.3 vs lib/generators/graphql/install_generator.rb in graphql-1.6.4

- old
+ new

@@ -66,11 +66,16 @@ class_option :batch, type: :boolean, default: false, desc: "Include GraphQL::Batch installation" + # These two options are taken from Rails' own generators' + class_option :api, + type: :boolean, + desc: "Preconfigure smaller stack for API only apps" + GRAPHIQL_ROUTE = <<-RUBY if Rails.env.development? mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/graphql" end RUBY @@ -81,21 +86,42 @@ template("query_type.erb", "app/graphql/types/query_type.rb") template("schema.erb", "app/graphql/#{schema_name.underscore}.rb") template("graphql_controller.erb", "app/controllers/graphql_controller.rb") route('post "/graphql", to: "graphql#execute"') - if !options[:skip_graphiql] - gem("graphiql-rails", group: :development) - route(GRAPHIQL_ROUTE) - end - if options[:batch] gem("graphql-batch") create_dir("app/graphql/loaders") end + + if options.api? + say("Skipped graphiql, as this rails project is API only") + say(" You may wish to use GraphiQL.app for development: https://github.com/skevy/graphiql-app") + elsif !options[:skip_graphiql] + gem("graphiql-rails", group: :development) + + # This is a little cheat just to get cleaner shell output: + log :route, 'graphiql-rails' + shell.mute do + route(GRAPHIQL_ROUTE) + end + end + + if gemfile_modified? + say "Gemfile has been modified, make sure you `bundle install`" + end end private + + def gemfile_modified? + @gemfile_modified + end + + def gem(*args) + @gemfile_modified = true + super(*args) + end def create_dir(dir) empty_directory(dir) if !options[:skip_keeps] create_file("#{dir}/.keep")