- Home
- Skills
- Ag0os
- Rails Dev Plugin
- Rails Graphql Patterns
rails-graphql-patterns_skill
3
GitHub Stars
2
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill ag0os/rails-dev-plugin --skill rails-graphql-patterns- patterns.md10.3 KB
- SKILL.md3.0 KB
Overview
This skill provides proven GraphQL patterns for Rails apps using the graphql-ruby gem. It guides schema design, type definitions, resolvers, mutations, subscriptions, and directory structure. The goal is predictable, performant APIs with clear conventions for authorization, error handling, and N+1 prevention.
How this skill works
The skill inspects code in app/graphql and related GraphQL files to suggest patterns and fixes. It recommends type signatures, nullability choices, resolver placement, DataLoader batching, and mutation return shapes. It also flags common problems like N+1 queries, missing authorization checks, and unstructured errors.
When to use it
- When designing or reviewing GraphQL schemas and types in Rails
- Implementing or refactoring queries, resolvers, or mutations
- Adding subscriptions or real-time updates to a Rails app
- Optimizing database access and preventing N+1 queries
- Adding field-level authorization or structured error handling
Best practices
- Define explicit types for every field and be deliberate with null: true/false
- Place business logic in resolvers or service objects, keep types thin
- Use graphql-ruby’s DataLoader to batch DB access and avoid N+1 problems
- Return structured error arrays from mutations instead of raising exceptions
- Authorize at the field or resolver level, not only at controller entry points
Example use cases
- Create a Post mutation that returns the created object and an errors array
- Define a UserType with computed fields using object methods and cached counts
- Implement a RecordLoader DataLoader source to batch user or post lookups
- Add subscriptions to broadcast new comments to clients in real time
- Refactor query fields into resolver classes for easier testing and reuse
FAQ
Use GraphQL::Dataloader with custom Source classes (e.g., RecordLoader) to batch and cache database fetches across fields.
Where should authorization checks live?
Perform authorization at the field or resolver level using context[:current_user] and policy methods so checks run for each resolved field.