Skip to content

Commit

Permalink
Check for Propshaft or Sprockets
Browse files Browse the repository at this point in the history
  • Loading branch information
rmosolgo committed Feb 23, 2024
1 parent 76634ce commit 01ff3e5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
21 changes: 13 additions & 8 deletions app/views/graphiql/rails/editors/show.html.erb
Expand Up @@ -2,14 +2,19 @@
<html>
<head>
<title><%= GraphiQL::Rails.config.title || 'GraphiQL' %></title>

<%= 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 %>
</head>
<body>
<%= content_tag :div, 'Loading...', id: 'graphiql-container', data: {
Expand Down
5 changes: 4 additions & 1 deletion test/controllers/editors_controller_test.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 01ff3e5

Please sign in to comment.