rmosolgo / graphiql-rails

Mount the GraphiQL query editor in a Rails app
MIT License
447 stars 135 forks source link

Remove Sprockets -- Updated #113

Closed scott-knight closed 7 months ago

scott-knight commented 10 months ago

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

  1. Removed sprockets as a dependency since it doesn't do anything in Rails 7+.
  2. Moved all file references to the view, which should also satisfy the needs of older versions of Rails.


Works like a charm

updated-graphiql

DougEdey commented 10 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

scott-knight commented 10 months ago

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:

Screenshot 2023-11-10 161805

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.

DougEdey commented 10 months ago

@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?

scott-knight commented 10 months ago

@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
jhirn commented 8 months ago

@scott-knight Confirmed working with propshaft gem. Rails 7.1.3.

You're a godsend I'm forking your branch for posterity.

uberjay commented 7 months ago

Thanks, this works for me! Much appreciated.

jmarsh24 commented 7 months ago

+1

rmosolgo commented 7 months ago

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.)

rmosolgo commented 7 months ago

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: