Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assets are not accessible in API-only app #13

Closed
ababich opened this issue Oct 6, 2016 · 14 comments
Closed

Assets are not accessible in API-only app #13

ababich opened this issue Oct 6, 2016 · 14 comments

Comments

@ababich
Copy link

ababich commented Oct 6, 2016

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

@ababich ababich changed the title Assets are not accessible from API-only app Assets are not accessible in API-only app Oct 6, 2016
@jam35L
Copy link

jam35L commented Oct 26, 2016

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
Copy link
Owner

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
Copy link

zfhui commented Jul 18, 2017

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
Copy link

@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
Copy link

jam35L commented Jul 31, 2017

@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
Copy link

yasser-sobhy commented Jul 31, 2017 via email

ryanmt added a commit to ryanmt/graphiql-rails that referenced this issue Mar 6, 2018
References rmosolgo#37:  Rails association should be more flexible now.
The runtime dependency on `railties` is required for Engine.

References rmosolgo#13: Having a runtime dependency on `sprockets-rails`
explicitly ensures that sprockets will be available for handling
application.{css,js} requests.
@luismu
Copy link

luismu commented Mar 26, 2018

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

@IvikGH
Copy link

IvikGH commented May 6, 2018

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
Copy link

IvikGH commented May 6, 2018

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

@FlorianBruniaux
Copy link

Thx @jam35L

@luizpicolo
Copy link

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

//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css

MITSUBOSHI added a commit to MITSUBOSHI/sample-graphql that referenced this issue May 17, 2020
@hdoan741
Copy link
Contributor

hdoan741 commented Jun 8, 2020

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
  1. Add require "sprockets/railtie" on top of config/development.rb config/application.rb
require "sprockets/railtie"
  1. 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!

hdoan741 added a commit to hdoan741/graphiql-rails that referenced this issue Jun 8, 2020
This is based on my experience setting up GraphiQL for a Rails 6 API app

See the detailed instructions in: rmosolgo#13 (comment)
TopDeveloper705 pushed a commit to TopDeveloper705/graphiql-rails that referenced this issue Dec 21, 2022
This is based on my experience setting up GraphiQL for a Rails 6 API app

See the detailed instructions in: rmosolgo/graphiql-rails#13 (comment)
@AdhamMoussa
Copy link

anyone managed to solve this on Rails 7 ??

@scott-knight
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests