https://github.com/rmosolgo/graphiql-rails
Mount the GraphiQL query editor in a Rails app
https://github.com/rmosolgo/graphiql-rails
Last synced: 6 days ago
JSON representation
Mount the GraphiQL query editor in a Rails app
- Host: GitHub
- URL: https://github.com/rmosolgo/graphiql-rails
- Owner: rmosolgo
- License: mit
- Created: 2016-01-05T02:54:57.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2025-04-01T13:34:51.000Z (14 days ago)
- Last Synced: 2025-04-02T02:04:56.011Z (13 days ago)
- Language: Ruby
- Homepage:
- Size: 5.81 MB
- Stars: 451
- Watchers: 13
- Forks: 140
- Open Issues: 12
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
- awesome-github-star - graphiql-rails
README
# GraphiQL-Rails [](https://badge.fury.io/rb/graphiql-rails) [](https://github.com/rmosolgo/graphiql-rails/actions/workflows/test.yml)
Mount the [GraphiQL IDE](https://github.com/graphql/graphiql) in Ruby on Rails.

## Installation
Add to your Gemfile:
```ruby
bundle add graphiql-rails
```## Usage
### Mount the Engine
Add the engine to `routes.rb`:
```ruby
# config/routes.rb
Rails.application.routes.draw do
# ...
if Rails.env.development?
mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/your/endpoint"
end
end
```- `at:` is the path where GraphiQL will be served. You can access GraphiQL by visiting that path in your app.
- `graphql_path:` is the path to the GraphQL endpoint. GraphiQL will send queries to this path.### Configuration
You can override `GraphiQL::Rails.config` values in an initializer (eg, `config/initializers/graphiql.rb`). The configs are:
- `query_params` (boolean, default `false`): if `true`, the GraphQL query string will be persisted the page's query params
- `initial_query` (string, default `nil`): if provided, it will be rendered in the query pane for a visitor's first visit
- `title` (string, default `nil`): if provided, it will be rendered in the page tag
- `logo` (string, default `nil`): if provided, it will be the text logo
- `csrf` (boolean, default `true`): include `X-CSRF-Token` in GraphiQL's HTTP requests
- `header_editor_enabled` (boolean, default `false`): if provided, the header editor will be rendered
- `headers` (hash, `String => Proc`): procs to fetch header values for GraphiQL's HTTP requests, in the form `(view_context) -> { ... }`. For example:```ruby
GraphiQL::Rails.config.headers['Authorization'] = -> (context) { "bearer #{context.cookies['_graphql_token']}" }
```- `input_value_deprecation` (boolean, default `false`): if provided, the deprecated arguments will be rendered
- `should_persist_headers` (boolean, default `nil`): if `true`, the headers in the editor will be persisted. If `false`, the toggle for 'Persist headers' will not be shown in the settings### Development
- Tests: `rake test`
- Build JS: `yarn run build`