Quick Start
Install Generator
Section titled “Install Generator”Run the install generator to scaffold your schema, controller, initializer, and resource directory:
rails generate quail:installThis creates:
app/graphql/app_schema.rb— your GraphQL schemaapp/graphql/resources/— where your resource files liveapp/graphql/mutations/— for custom mutation classesapp/graphql/queries/— for custom query resolversapp/graphql/subscriptions/— for custom subscription classesapp/graphql/types/— for custom GraphQL typesapp/controllers/graphql_controller.rb— a ready-to-go controllerapp/channels/graphql_channel.rb— ActionCable channel for subscriptionsconfig/initializers/quail.rb— configuration- A
POST /graphqlroute
Generator Options
Section titled “Generator Options”Customize the install generator to fit your setup:
rails generate quail:install --schema-name=MySchema # custom schema class namerails generate quail:install --skip-controller # skip controller generationrails generate quail:install --skip-channel # skip ActionCable channelCreate Your First Resource
Section titled “Create Your First Resource”Generate a resource for an existing model:
rails generate quail:resource ArticleOr 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, :bodyendThat single file gives you:
- An
ArticleTypeGraphQL type with all declared fields and associations article(id: ID!)andarticlesqueries (with Relay connection pagination)articleCreate,articleUpdate,articleDeletemutations- Writable attributes scoped to only what you allow
Resource Generator Options
Section titled “Resource Generator Options”You can also pass options directly to the resource generator:
rails generate quail:resource Article \ --attributes=id title body \ --skip-mutations=delete \ --subscribe-on=create updateNext Steps
Section titled “Next Steps”- Learn about the Resources DSL for associations, polymorphic types, and computed attributes
- Configure Mutations and Queries to customize your API
- Set up Subscriptions for real-time updates via ActionCable