Skip to content

Quick Start

Run the install generator to scaffold your schema, controller, initializer, and resource directory:

Terminal window
rails generate quail:install

This creates:

  • app/graphql/app_schema.rb — your GraphQL schema
  • app/graphql/resources/ — where your resource files live
  • app/graphql/mutations/ — for custom mutation classes
  • app/graphql/queries/ — for custom query resolvers
  • app/graphql/subscriptions/ — for custom subscription classes
  • app/graphql/types/ — for custom GraphQL types
  • app/controllers/graphql_controller.rb — a ready-to-go controller
  • app/channels/graphql_channel.rb — ActionCable channel for subscriptions
  • config/initializers/quail.rb — configuration
  • A POST /graphql route

Customize the install generator to fit your setup:

Terminal window
rails generate quail:install --schema-name=MySchema # custom schema class name
rails generate quail:install --skip-controller # skip controller generation
rails generate quail:install --skip-channel # skip ActionCable channel

Generate a resource for an existing model:

Terminal window
rails generate quail:resource Article

Or write one by hand in app/graphql/resources/:

class ArticleResource
include Quail::Resource
attributes :id, :title, :body, :published_at
has_many :comments
belongs_to :author
writable_attributes :title, :body
end

That single file gives you:

  • An ArticleType GraphQL type with all declared fields and associations
  • article(id: ID!) and articles queries (with Relay connection pagination)
  • articleCreate, articleUpdate, articleDelete mutations
  • Writable attributes scoped to only what you allow

You can also pass options directly to the resource generator:

Terminal window
rails generate quail:resource Article \
--attributes=id title body \
--skip-mutations=delete \
--subscribe-on=create update