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

SOLVED: Work with API only app #53

Closed
sarink opened this issue Jul 30, 2018 · 10 comments
Closed

SOLVED: Work with API only app #53

sarink opened this issue Jul 30, 2018 · 10 comments

Comments

@sarink
Copy link

sarink commented Jul 30, 2018

I'm encountering this issue #42 and I believe that the problem is due to using a rails 5 api only app.

Tried following these instructions #13 (comment) but they appear to be outdated.

Is there any way to make this gem work with an API app?

@sarink
Copy link
Author

sarink commented Jul 31, 2018

Update: Figured this out myself. The only thing necessary (rails 5.2.0) is to add the following lines to application.rb

require "sprockets/railtie"

config.middleware.use Rack::MethodOverride

Closing. But it might be nice to add it to the readme!

@sarink sarink closed this as completed Jul 31, 2018
@sarink sarink changed the title Work with API only app SOLVED: Work with API only app Jul 31, 2018
@rmosolgo
Copy link
Owner

Glad you found a solution, and thanks for sharing it! Feel free to open a PR to the readme if you're interested.

@Li357
Copy link

Li357 commented Oct 29, 2019

If you're experiencing the error:

Expected to find a manifest file in `app/assets/config/manifest.js` (Sprockets::Railtie::ManifestNeededError)

With Rails 6/Sprockets 4, downgrade to Sprockets 3 by adding this to your Gemfile:

gem 'sprockets', '~> 3'

And running bundle update sprockets

@aharasta
Copy link

People starting new projects with Rails 6 in API mode will encounter issue @Li357 has pointed out. Thanks for the solution!

@Aryk
Copy link

Aryk commented Jan 7, 2020

Thanks @Li357! gem 'sprockets', '~> 3' worked!

@JamesLivengood
Copy link

JamesLivengood commented Jan 20, 2020

For anyone getting this error, because your Rails app is API-only:
No route matches [GET] "/graphiql"
You need to temporarily update config.api_only to be false (in application.rb). Then you can re-run spring rails generate graphql:install and it will generate what you need.

It also can be done manually, by adding

gem 'graphiql-rails', group: :development

to your Gemfile and

if Rails.env.development?
  mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/graphql"
end

to routes.rb

@areph
Copy link

areph commented Jan 21, 2020

Thanks @Li357!

@hdoan741
Copy link
Contributor

hdoan741 commented Jun 8, 2020

You don't need to downgrade sprocket, just add a manifest.js file and it'll work:
See: #13 (comment)

@RobertWSaunders
Copy link
Contributor

FYI, if you don't want to run on a lower sprockets version you can just do:

  1. Create the manifest file:

touch app/assets/config/manifest.js

  1. Add links to the GraphiQL CSS and JS files so they get loaded:
//= link graphiql/rails/application.css
//= link graphiql/rails/application.js

RobertWSaunders added a commit to RobertWSaunders/graphiql-rails that referenced this issue Jul 11, 2021
With the latest Rails version (and more specifically, an updated Sprockets version) there is additional steps required to properly mount GraphiQL.

See rmosolgo#53 (comment).
@redferret
Copy link

Update: Figured this out myself. The only thing necessary (rails 5.2.0) is to add the following lines to application.rb

require "sprockets/railtie"

config.middleware.use Rack::MethodOverride

Closing. But it might be nice to add it to the readme!

Can you explain why you picked this?
Reading in the docs I find this for Rack::MethodOverride

Allows the method to be overridden if params[:_method] is set. This is the middleware which supports the PUT and DELETE HTTP method types.

TopDeveloper705 pushed a commit to TopDeveloper705/graphiql-rails that referenced this issue Dec 21, 2022
With the latest Rails version (and more specifically, an updated Sprockets version) there is additional steps required to properly mount GraphiQL.

See rmosolgo/graphiql-rails#53 (comment).
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

10 participants