Home

Awesome

GraphiQL-Rails Gem Version Tests

Mount the GraphiQL IDE in Ruby on Rails.

image

Installation

Add to your Gemfile:

bundle add graphiql-rails

Additionally, you'll need Sprockets or Propshaft to serve the JS and CSS assets.

Usage

Mount the Engine

Add the engine to routes.rb:

# config/routes.rb
Rails.application.routes.draw do
  # ...
  if Rails.env.development?
    mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/your/endpoint"
  end
end

Sprockets or Propshaft

You'll need Sprockets or Propshaft to deliver the JS and CSS for GraphiQL. If you don't already have one of those, you can add them with:

$ bundle add sprockets-rails
# or
$ bundle add propshaft

API Mode

If you're using Rails 6+ in "API mode", you'll also need to do the following:

  1. Add require "sprockets/railtie" to your application.rb.

  2. Create an app/assets/config/manifest.js file and add the following:

//= link graphiql/rails/application.css
//= link graphiql/rails/application.js

Configuration

You can override GraphiQL::Rails.config values in an initializer (eg, config/initializers/graphiql.rb). The configs are:

Development