rmosolgo / graphiql-rails

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

Assets are not accessible in API-only app #13

Closed ababich closed 7 years ago

ababich commented 7 years ago

If you add GraphiQL Rails to pura Rails API app you will not get it working as assets are not accessible:

ActionController::RoutingError (No route matches [GET] "/stylesheets/graphiql/rails/application.css"):
ActionController::RoutingError (No route matches [GET] "/javascripts/graphiql/rails/application.js"):

I'm pretty sure this is API-only issue, documentation how to make it working should be improved

jam35L commented 7 years ago

For those wanting to make this work on the API only rails app. Add the following to your Gemfile.

gem 'sass-rails'
gem 'uglifier'
gem 'coffee-rails'

And un comment or add the following to your application.rb require "sprockets/railtie"

rmosolgo commented 7 years ago

Thanks for following up! I guess this gem depends on sprockets routing being hooked up. Feel free to PR the documentation if you can think of a way to explain that clearly.

zfhui commented 7 years ago

I left out adding the assets related gems (sass-rails, uglifier, coffee-rails) to my API only Rails app (v5.1.2) & graphiql seems to work fine. 😉

yasser-sobhy commented 7 years ago

@jam35L I need to serve images uploaded using Carrierwave in an API-only app, so I uncommented require "sprockets/railtie" but it's still not working even with sass-rails, uglifier, coffee-rails gems, any ideas?

jam35L commented 7 years ago

@yasser-sobhy Please clarify which part is not working. Your API only app is not working or you can't access your images?

yasser-sobhy commented 7 years ago

The images wasn't working, but it's working now. Thank you

On Jul 31, 2017 7:12 AM, "James Lo" notifications@github.com wrote:

@yasser-sobhy https://github.com/yasser-sobhy Please clarify which part is not working. Your API only app is not working or you can't access your images?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/rmosolgo/graphiql-rails/issues/13#issuecomment-318962997, or mute the thread https://github.com/notifications/unsubscribe-auth/AFcbhK2aMfi3NLea4tusMIOhUOZ2rJ4rks5sTVQ-gaJpZM4KPn7E .

luismu commented 6 years ago

@zfhui Did you have your rails app in api mode?

IvikGH commented 6 years ago

Hi. I have the same issue. I have Rails API only app. And i can't add styles with app/assets/stylesheets/application.scss. I don't see any request for css/js file even after adding gem 'sass-rails', gem 'uglifier', gem 'coffee-rails', require "sprockets/railtie" and even adding application.html.haml. rake assets:precompile creates the application...css but not request for that file comes.

IvikGH commented 6 years ago

The problem was that i've added application.html.haml not to app/views/layouts/ folder. Now everything is OK.

FlorianBruniaux commented 6 years ago

Thx @jam35L

luizpicolo commented 4 years ago

For rails 6 create app/assets/config/manifest.js and add

//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
hdoan741 commented 4 years ago

Just got graphiql-rails to work with my Rails 6, API only app, and here are the steps I took:

  1. Adding graphiql-rails Gemfile. It works without uglifier, coffee-rails and sass-rails.
    group :development do
    ...
    gem "graphiql-rails"
    end

    and add to routes.rb like in README.

    if Rails.env.development?
    mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/graphql"
    end
  2. Add require "sprockets/railtie" on top of ~config/development.rb~ config/application.rb
    require "sprockets/railtie"
  3. Sprockets will complain that manifest.js is needed. Here is the simplest version that works, based on @MITSUBOSHI changes
    --- add to `app/assets/config/manifest.js`
    //= link graphiql/rails/application.css
    //= link graphiql/rails/application.js

And it works!

AdhamMoussa commented 1 year ago

anyone managed to solve this on Rails 7 ??

scott-knight commented 1 year ago

anyone managed to solve this on Rails 7 ??

I created a PR for this over a year ago, but has been ignored. The fix is pretty simple. My PR has fallen out of sync with main. The maintainers should fix this ASAP as including Sprockets in Rails 7 does not work and is ill advised.