writing-graphql-operations
БесплатноБез исполняемых скриптовНе проверенCreates GraphQL queries and mutations using gql.tada and urql. Use when writing operations, implementing repositories, updating schema, or testing GraphQL code.
Об этом скилле
GraphQL Operations Developer
Overview
Guide the creation and maintenance of GraphQL operations following project conventions for type safety, organization, error handling, and testing with gql.tada and urql.
When to Use
- Creating new GraphQL queries or mutations
- Integrating with Saleor API endpoints
- Updating schema after Saleor changes
- Working with urql client configuration
- Creating MSW mocks for testing
Quick Reference
| Tool | Purpose |
|---|---|
| gql.tada | Type-safe GraphQL with TypeScript inference |
| urql | GraphQL client with caching |
| @urql/exchange-auth | Authentication (Bearer token) |
| @urql/exchange-retry | Rate limit retry (429, max 5 attempts) |
File Organization
src/lib/graphql/
├── client.ts # urql client configuration
├── operations/ # GraphQL operation definitions
├── fragments/ # Reusable GraphQL fragments
├── __mocks__/ # MSW test mocks
└── schema.graphql # Saleor schema (generated)
src/modules/<entity>/
├── repository.ts # Uses GraphQL operations
└── ...
Creating Operations
Use gql.tada for all operations. Types are inferred from schema automatically:
import { graphql } from 'gql.tada';
export const GetCategoriesQuery = graphql(`
query GetCategories($first: Int!) {
categories(first: $first) {
edges {
node { id, name, slug, description }
}
}
}
`);
// Type inferred automatically
type GetCategoriesResult = ResultOf<typeof GetCategoriesQuery>;
For shared fields, extract fragments and pass as second argument to graphql().
Repository Pattern
Each entity has a repository class that encapsulates GraphQL operations and maps responses to domain models:
export class CategoryRepository {
constructor(private readonly client: Client) {}
async findAll(): Promise<Category[]> {
const result = await this.client.query(GetCategoriesQuery, { first: 100 });
if (result.error) {
throw GraphQLError.fromCombinedError(result.error, 'GetCategories');
}
return this.mapCategories(result.data?.categories);
}
async create(input: CategoryInput): Promise<Category> {
const result = await this.client.mutation(CreateCategoryMutation, { input });
if (result.error) {
throw GraphQLError.fromCombinedError(result.error, 'CreateCategory');
}
if (result.data?.categoryCreate?.errors?.length) {
throw new GraphQLError('Category creation failed', result.data.categoryCreate.errors);
}
return this.mapCategory(result.data?.categoryCreate?.category);
}
}
Key pattern: Always map GraphQL responses to domain models in the repository. Never expose GraphQL types to services.
Error Handling
Two error types to always check:
- Network/GraphQL errors (
result.error): Wrap withGraphQLError.fromCombinedError(error, 'OperationName', { context }) - Mutation validation errors (
result.data?.mutation?.errors): Check array length, throw with field details
See references/error-handling.md for complete error patterns, classification, and MSW error mocking.
Schema Management
pnpm fetch-schema # Updates schema.graphql and graphql-env.d.ts
Update schema when: new Saleor features needed, after Saleor version upgrade, or when encountering schema drift errors. Always commit schema changes with the feature implementation.
Testing
Mock GraphQL operations with MSW using graphql.query() and graphql.mutation() handlers. See analyzing-test-coverage skill for full MSW setup patterns.
Client Configuration
The urql client is configured in src/lib/graphql/client.ts with: cacheExchange, authExchange (Bearer token), retryExchange (1s-15s backoff, 5 attempts, retries on 429 and network errors), and fetchExchange.
Best Practices
Do:
- Use
gql.tadafor all operations (automatic type inference) - Keep operations close to their domain modules
- Map GraphQL responses to domain models in repository
- Include operation name in error context
- Update mocks when schema changes
- Extract shared fields to fragments
Don't:
- Use raw string queries (no type safety)
- Expose GraphQL types directly to services
- Skip error handling for any operation
- Hardcode pagination limits (use constants)
Validation Checkpoints
| Phase | Validate | Command |
|---|---|---|
| Schema fresh | No drift | pnpm fetch-schema |
| Operations typed | gql.tada inference | Check IDE types |
| Mocks match | MSW handlers | pnpm test |
| Error handling | All paths covered | Code review |
Common Mistakes
| Mistake | Fix |
|---|---|
Not checking errors array |
Always check result.data?.mutation?.errors |
| Exposing GraphQL types | Map to domain types in repository |
| Missing error context | Include operation name in errors |
| Stale schema | Run pnpm fetch-schema aft |
Установить writing-graphql-operations в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadGrepGlobWriteEditВложенные файлы
FAQ
Что делает скилл writing-graphql-operations?
Creates GraphQL queries and mutations using gql.tada and urql. Use when writing operations, implementing repositories, updating schema, or testing GraphQL code.
Как установить скилл writing-graphql-operations?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл writing-graphql-operations запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic