Rails GraphQL is distributed as a Ruby gem and integrates seamlessly with Rails applications. This guide covers installation, configuration, and verification.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/virtualshield/rails-graphql/llms.txt
Use this file to discover all available pages before exploring further.
Requirements
Before installing Rails GraphQL, ensure your environment meets these requirements:Rails
Rails 6.0 or higherRails GraphQL is built to integrate with modern Rails conventions
Ruby
Ruby 2.6.3 or higherRequired for the C-based parser to compile correctly
Rails GraphQL uses a custom C-based parser for exceptional performance. The gem will compile native extensions during installation.
Installation
Add the gem
Add Rails GraphQL to your Gemfile:Or add it manually to your Then install:
Gemfile:Gemfile
Run the generator
Rails GraphQL provides a generator to set up the basic structure:This generator creates:
app/graphql/app_schema.rb- Your main GraphQL schemaapp/controllers/graphql_controller.rb- Controller for handling GraphQL requests- Route configuration in
config/routes.rb
Configure the route
The generator adds a route to You can customize the endpoint path as needed:
config/routes.rb:config/routes.rb
config/routes.rb
Directory structure
After installation, your GraphQL code lives inapp/graphql/. This directory works differently from standard Rails folders:
These directories are not created automatically. Create them as needed when organizing your GraphQL schema.
Module structure
All GraphQL classes must be inside theGraphQL module to avoid naming collisions:
app/graphql/objects/user.rb
This structure is 100% compatible with Zeitwerk, Rails’ autoloader.
Configuration options
Rails GraphQL provides several configuration options. Create an initializer to customize behavior:config/initializers/graphql.rb
Schema-specific configuration
You can also configure individual schemas:app/graphql/app_schema.rb
Controller setup
The generated controller includes theGraphQL::Controller module:
app/controllers/graphql_controller.rb
Adding authentication
You can add authentication to your GraphQL controller:app/controllers/graphql_controller.rb
Using generators
Rails GraphQL provides several generators to speed up development:Next steps
Now that Rails GraphQL is installed, you’re ready to build your first schema:Quickstart
Build your first GraphQL query
Architecture
Understand how Rails GraphQL works