From 01ff3e520dc09dfb8aa5d6798ba1eb5d06c10e2e Mon Sep 17 00:00:00 2001 From: Robert Mosolgo Date: Fri, 23 Feb 2024 13:33:02 -0500 Subject: [PATCH] Check for Propshaft or Sprockets --- .../graphiql/rails/editors/show.html.erb | 21 ++++++++++++------- test/controllers/editors_controller_test.rb | 5 ++++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/app/views/graphiql/rails/editors/show.html.erb b/app/views/graphiql/rails/editors/show.html.erb index 2765500..575e604 100644 --- a/app/views/graphiql/rails/editors/show.html.erb +++ b/app/views/graphiql/rails/editors/show.html.erb @@ -2,14 +2,19 @@ <%= GraphiQL::Rails.config.title || 'GraphiQL' %> - - <%= stylesheet_link_tag("graphiql/rails/graphiql-2.4.0") %> - <%= stylesheet_link_tag("graphiql/rails/application") %> - <%= javascript_include_tag("graphiql/rails/react-17.0.2", nonce: true ) %> - <%= javascript_include_tag("graphiql/rails/react-dom-17.0.2", nonce: true ) %> - <%= javascript_include_tag("graphiql/rails/fetch-0.10.1", nonce: true ) %> - <%= javascript_include_tag("graphiql/rails/graphiql-2.4.0", nonce: true ) %> - <%= javascript_include_tag("graphiql/rails/graphiql_show", nonce: true ) %> + <% if defined?(Propshaft) %> + <%= stylesheet_link_tag("graphiql/rails/graphiql-3.1.1") %> + <%= stylesheet_link_tag("graphiql/rails/application") %> + <%= javascript_include_tag("graphiql/rails/react-18.2.0", nonce: true ) %> + <%= javascript_include_tag("graphiql/rails/react-dom-18.2.0", nonce: true ) %> + <%= javascript_include_tag("graphiql/rails/graphiql-3.1.1", nonce: true ) %> + <%= javascript_include_tag("graphiql/rails/graphiql_show", nonce: true ) %> + <% elsif defined?(Sprockets) %> + <%= stylesheet_link_tag("graphiql/rails/application") %> + <%= javascript_include_tag("graphiql/rails/application", nonce: true ) %> + <% else %> + <% raise "GraphiQL::Rails requires either Propshaft or Sprockets. Use `$ bundle add propshaft` or `$ bundle add sprockets-rails` to add one of them to your app." %> + <% end %> <%= content_tag :div, 'Loading...', id: 'graphiql-container', data: { diff --git a/test/controllers/editors_controller_test.rb b/test/controllers/editors_controller_test.rb index 36885e7..96b8d53 100644 --- a/test/controllers/editors_controller_test.rb +++ b/test/controllers/editors_controller_test.rb @@ -5,6 +5,7 @@ module Rails class EditorsControllerTest < ActionController::TestCase setup do @routes = GraphiQL::Rails::Engine.routes + Object.const_set(:Sprockets, :something) end teardown do @@ -13,6 +14,7 @@ class EditorsControllerTest < ActionController::TestCase GraphiQL::Rails.config.title = nil GraphiQL::Rails.config.logo = nil GraphiQL::Rails.config.headers = {} + Object.send(:remove_const, :Sprockets) end def graphql_params @@ -23,7 +25,8 @@ def graphql_params get :show, **graphql_params assert_response(:success) assert_includes(@response.body, 'my/endpoint', 'it uses the provided path') - assert_match(/application-\w+\.js/, @response.body, 'it includes assets') + # If sprockets was actually loaded, it would apply a digest to this: + assert_match(/application\.js/, @response.body, 'it includes assets') end test 'it uses initial_query config' do