Closed scott-knight closed 7 months ago
Are there additional missing steps for this? I tried to use this changeset and I get missing assets still:
eg: ActionController::UrlGenerationError (No route matches {:action=>"show", :controller=>"graphiql", :format=>"js", :path=>"javascripts/graphiql/rails/graphiql_show"}):
Note: I am using Vite if that provides any help
Hi @DougEdey.
I don't have anything extra in my setup... Here is what I have (I'm also running Vite 5):
Added to my Gemfile:
gem 'graphiql-rails', git: 'https://github.com/scott-knight/graphiql-rails.git', branch: 'fix-assets-remove-sprokets'
In my config/routes.rb
file:
if Rails.env.development?
mount GraphiQL::Rails::Engine, at: 'graphiql', graphql_path: 'api/v1/graphql'
end
post 'api/v1/graphql', to: 'api/v1/graphql#execute'
Open the route in the browser, and boom:
Looking at the error you have... it looks like you're trying to instantiate the graphiql code through a view :format=>"js
and that isn't necessary. You can simply hit the endpoint defined by the gem and the route in the routes file.
@scott-knight Yeah the error from Rails isn't really helpful, the initial page loads fine but the assets (css
and js
) are the ones producing the 404
What do you use to serve assets in your app?
@DougEdey -- I have propshaft
installed with my gems in my Gemfile as well. Maybe that's what you're missing:
# ------ ASSETS/JS/CSS -------------------
gem 'propshaft' # https://github.com/rails/propshaft
gem 'vite_rails' # https://github.com/ElMassimo/vite_ruby
@scott-knight Confirmed working with propshaft
gem. Rails 7.1.3.
You're a godsend I'm forking your branch for posterity.
Thanks, this works for me! Much appreciated.
+1
Hey @scott-knight , thanks for your work on this! I definitely want to support non-Sprockets installations.
I have a question about your premise:
Sprockets doesn't integrate with Rails 7+ ... Sprockets is retired, no longer supported, and shouldn't be used.
I tested a rails new
with 7.1.2 and sprockets-rails
was in the gemfile. Also, the Rails guides still include information about using sprockets: https://guides.rubyonrails.org/asset_pipeline.html#how-to-use-sprockets
Could you share some background on why you think Sprockets doesn't integrate with Rails 7+ or on why you think sprockets is deprecated?
In any case, I'm totally game to support a propshaft-based approach, but I want to make sure I'm not missing anything before I pursue these changes.
(I think we'd need to make sure propshaft is present somehow, too, along with the changes here.)
I pulled your commits into #116 and retained Sprockets support, with a runtime check to make sure one of the required libraries was present :+1:
Summary
Closed the original PR which removes Sprockets from this gem (since Sprockets doesn't integrate with Rails 7+). This PR is an update, using the current code from this gem. forked repo
Reason
Updates
Works like a charm