用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/mikailustuner/OmniRule --skill graphql-patterns命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | graphql-patterns |
| description | GraphQL: Schema design, resolvers, pagination, caching, subscriptions, vs REST decisions |
| triggers | {"extensions":[".graphql",".gql",".ts"],"keywords":["GraphQL","query","mutation","resolver","schema","Apollo","DataLoader"]} |
| auto_load_when | Building GraphQL APIs or clients |
| agent | architect |
| tools | ["Read","Write","Bash"] |
Focus: When to choose GraphQL, schema architecture, data fetching strategies
Choose GraphQL when:
├── Multiple clients (web, mobile, TV) with different needs
├── Complex domain with many related entities
├── Client needs flexible queries (dashboard builders)
└── Frequent mobile bandwidth constraints
Choose REST when:
├── Simple CRUD operations
├── Public API with stable, predictable responses
├── Caching at CDN level is critical
└── Team unfamiliar with GraphQL
Schema structure:
├── Query: read operations
├── Mutation: write operations
├── Subscription: real-time updates
└── Types: objects, inputs, enums, scalars
Naming conventions:
├── Nouns for types (User, Order)
├── Verbs for operations (createUser, updateOrder)
├── Use plural for lists (users, orders)
└── Prefix mutations with action (create, update, delete)
Offset-based (simple):
├── Arguments: first, after (cursor), last, before
├── Good for: sequential browsing
└── Problem: expensive on large offsets
Cursor-based (efficient):
├── Use: opaque cursor string
├── Good for: infinite scroll, large datasets
└── Never expose DB IDs directly
Connection pattern:
├── nodes: actual data array
├── pageInfo: hasNextPage, hasPreviousPage, startCursor, endCursor
└── Standardized: relay-spec compatible
Client-side:
├── Normalized cache (Apollo Client)
├── Key by type + ID
└── Optimistic updates
Server-side:
├── DataLoader: batch + cache
├── Use for: N+1 prevention
└── Per-request caching
CDN challenges:
├── Complex: varies by query
└── Solution: persisted queries, POST cache
Implementation options:
├── WebSockets: full-duplex, persistent
├── Server-Sent Events: one-way, simpler
└── Polling: fallback, simple
Design patterns:
├── Subscribe to entity changes (userUpdated)
├── Subscribe to collections (newOrders)
└── Subscribe to global events (broadcast)
Reconnection:
├── Exponential backoff
├── Resume with last known state
└── Refetch on disconnect
Resolver structure:
├── Root (previous result)
├── Args (query arguments)
├── Context (auth, services)
└── Info (query metadata)
DataLoader pattern:
├── Batch: collect IDs across field resolution
├── Cache: dedupe within request
└── Promise: async resolution
Error handling:
├── GraphQL errors: partial data, error array
└── Security: never leak internal errors
❌ N+1 queries — resolver fetches per-item inside list
✅ Use DataLoader to batch & deduplicate DB calls
❌ Returning full objects when client needs 2 fields
✅ Let GraphQL projection do the work; never over-fetch in resolvers
❌ Deeply nested mutations that do too much
✅ Single-responsibility mutations, max 2 levels deep
❌ No query depth/complexity limits
✅ Set max depth (10) and max complexity (1000) per query
❌ Exposing internal DB IDs as GraphQL IDs directly
✅ Opaque cursor-based IDs for relay-compatible pagination
| Scenario | Solution | Library |
|---|---|---|
| Batch DB calls | DataLoader | dataloader |
| Input validation | Input types + Zod/yup | graphql-shield |
| Auth per field | Field-level directives | graphql-shield |
| Real-time | Subscriptions over WS | graphql-ws |
| File upload | multipart request | graphql-upload |
| Schema-first | SDL + codegen | @graphql-codegen |
| Code-first | Resolver decorators | TypeGraphQL / Pothos |