rmosolgo / graphiql-rails

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

SOLVED: Work with API only app #53

Closed sarink closed 6 years ago

sarink commented 6 years ago

I'm encountering this issue https://github.com/rmosolgo/graphiql-rails/issues/42 and I believe that the problem is due to using a rails 5 api only app.

Tried following these instructions https://github.com/rmosolgo/graphiql-rails/issues/13#issuecomment-256256255 but they appear to be outdated.

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

sarink commented 6 years ago

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!

rmosolgo commented 6 years ago

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

Li357 commented 5 years ago

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 commented 5 years ago

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

Aryk commented 4 years ago

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

JamesLivengood commented 4 years ago

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 commented 4 years ago

Thanks @Li357!

hdoan741 commented 4 years ago

You don't need to downgrade sprocket, just add a manifest.js file and it'll work: See: https://github.com/rmosolgo/graphiql-rails/issues/13#issuecomment-640366886

RobertWSaunders commented 3 years ago

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
redferret commented 3 years ago

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.