Skip to main content
Rails GraphQL provides a set of generators to help you quickly scaffold your GraphQL application. These generators create the necessary files and folder structure to get you started.

graphql:install

Add an initial setup to your application with configuration, schema, folder structure, and routes.

Usage

rails g graphql:install

Arguments

schema
string
default:"AppSchema"
The name of the schema to create

Options

directory
string
default:"app/graphql"
Where to put the GraphQL files
skip_keeps
boolean
default:"false"
Skip creating .keep files and respective folders
skip_routes
boolean
default:"false"
Skip adding GraphQL routes

What It Creates

The install generator creates the following structure:
app/
  graphql/
    directives/
    enums/
    fields/
    inputs/
    interfaces/
    mutations/
    object/
    queries/
    scalars/
    sources/
    subscriptions/
    unions/
    app_schema.rb
config/
  initializers/
    graphql.rb
  routes.rb

Generated Routes

The following routes are added to config/routes.rb:
config/routes.rb
get  "/graphql/describe", to: "graphql/base#describe"
get  "/graphiql",         to: "graphql/base#graphiql"
post "/graphql",          to: "graphql/base#execute"

Configuration File

The generator creates config/initializers/graphql.rb with common settings:
config/initializers/graphql.rb
Rails::GraphQL.configure do |config|
  # Enable introspection (disabled in production by default)
  config.enable_introspection = !Rails.env.production?

  # Enable I18n descriptions for multi-language documentation
  config.enable_i18n_descriptions = true

  # Additional configuration options available...
end
The install generator automatically invokes the graphql:schema generator to create your main schema file.

graphql:schema

Create a new GraphQL schema inside the graphql folder.

Usage

rails g graphql:schema SampleSchema

Arguments

schema
string
default:"AppSchema"
The name of the schema to create

Options

directory
string
default:"app/graphql"
Where to put the schema file

Generated Schema

app/graphql/sample_schema.rb
module GraphQL
  class SampleSchema < GraphQL::Schema
  end
end
The generated schema inherits from GraphQL::Schema and is ready for customization with queries, mutations, and subscriptions.

Learn more about schemas

Understand how to configure and customize your GraphQL schemas

graphql:controller

Create a new controller that handles GraphQL requests with the GraphQL::Controller concern.

Usage

rails g graphql:controller SampleController

Arguments

name
string
default:"GraphQLController"
The name of the controller to create

Generated Controller

app/controllers/sample_controller.rb
class SampleController < ApplicationController
  include GraphQL::Controller
end
The GraphQL::Controller concern provides methods for:
  • Executing GraphQL queries
  • Handling introspection requests
  • Serving GraphiQL interface
  • Managing request context

Customize your controller

Learn how to customize the GraphQL controller for your needs

graphql:channel

Create a new Action Cable channel for GraphQL subscriptions with the GraphQL::Channel concern.

Usage

rails g graphql:channel SampleChannel

Arguments

name
string
default:"GraphQLChannel"
The name of the channel to create

Generated Channel

app/channels/sample_channel.rb
class SampleChannel < ApplicationCable::Channel
  include GraphQL::Channel
end
The GraphQL::Channel concern enables real-time GraphQL subscriptions over WebSockets using Action Cable.

Customize your channel

Explore channel customization options for subscriptions
More generators will be delivered for version 1.0.0, including generators for types, fields, and other GraphQL components.

Build docs developers (and LLMs) love