用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/pluginagentmarketplace/custom-plugin-graphql --skill graphql-schema-design命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Build React apps with Apollo Client - queries, mutations, cache, and subscriptions
Build production GraphQL servers with Apollo Server, plugins, and federation
Generate TypeScript types and React hooks from GraphQL schemas
基于 SOC 职业分类
正在显示 SKILL.md
| name | graphql-schema-design |
| description | Design production-grade GraphQL schemas with best practices and patterns |
| sasmp_version | 1.3.0 |
| bonded_agent | 02-graphql-schema |
| bond_type | PRIMARY_BOND |
| version | 2.0.0 |
| complexity | intermediate |
| estimated_time | 3-5 hours |
| prerequisites | ["graphql-fundamentals"] |
Architect scalable, maintainable GraphQL APIs
Learn industry-standard patterns for designing GraphQL schemas that scale. Covers naming conventions, pagination, error handling, and schema evolution.
| Pattern | When to Use | Example |
|---|---|---|
| Connection | Paginated lists | users: UserConnection! |
| Payload | Mutation results | CreateUserPayload |
| Input | Mutation args | CreateUserInput |
| Interface | Shared fields | interface Node { id: ID! } |
| Union | Multiple types | SearchResult = User | Post |
# Types: PascalCase
type User { }
type UserProfile { }
# Fields: camelCase
type User {
firstName: String!
lastName: String!
createdAt: DateTime!
isActive: Boolean! # Boolean prefix: is, has, can
}
# Queries: noun (singular/plural)
type Query {
user( ID User
UserConnection
createUser CreateUserInput CreateUserPayload
updateUser ID, UpdateUserInput UpdateUserPayload
deleteUser ID DeleteUserPayload
sendEmail SendEmailInput SendEmailPayload
publishPost ID PublishPostPayload
CreateUserInput
UpdateUserInput
UserFilterInput
CreateUserPayload
UpdateUserPayload
# Connection pattern
type Query {
users(
first: Int
after: String
last: Int
before: String
filter: UserFilter
): UserConnection!
}
type UserConnection {
edges: [UserEdge!]!
pageInfo: PageInfo!
totalCount: Int!
}
type UserEdge {
node: User!
cursor: String!
}
type PageInfo {
hasNextPage: Boolean!
hasPreviousPage: Boolean!
startCursor: String
endCursor: String
}
# Usage
query GetUsers {
users(first: 10, after: "cursor123") {
edges {
node { id name }
cursor
}
pageInfo {
hasNextPage
endCursor
}
}
}
# Payload pattern (recommended)
type CreateUserPayload {
user: User
errors: [UserError!]!
}
type UserError {
field: String
message: String!
code: UserErrorCode!
}
enum UserErrorCode {
INVALID_EMAIL
DUPLICATE_EMAIL
WEAK_PASSWORD
NOT_FOUND
UNAUTHORIZED
}
# Union pattern (type-safe)
union CreateUserResult =
| CreateUserSuccess
| ValidationError
| NotAuthorizedError
type CreateUserSuccess {
user: User!
}
type ValidationError {
field: String!
message: String!
}
type NotAuthorizedError {
message: String!
}
type Mutation {
createUser(input: CreateUserInput!): CreateUserResult!
}
# Global object identification
interface Node {
id: ID!
}
type Query {
node(id: ID!): Node
nodes(ids: [ID!]!): [Node]!
}
type User implements Node {
id: ID!
name: String!
}
type Post implements Node {
id: ID!
title: String!
}
# Enables refetching any object by ID
query RefetchUser {
node(id: "User:123") {
... on User {
name
email
}
}
}
# schema.graphql (root)
type Query {
# User domain
user(id: ID!): User
users(filter: UserFilter): UserConnection!
# Product domain
product(id: ID!): Product
products(filter: ProductFilter): ProductConnection!
}
type Mutation {
# User mutations
createUser(input: CreateUserInput!): CreateUserPayload!
updateUser(id: ID!, input: UpdateUserInput!): UpdateUserPayload!
# Product mutations
createProduct(input: CreateProductInput!): CreateProductPayload!
}
# types/user.graphql
type User implements Node {
id: ID!
email: String!
name: String!
createdAt: DateTime!
orders: OrderConnection!
}
# types/product.graphql
type Product implements Node {
id: ID!
name: String!
price: Money!
inventory: Int!
}
Returning a list?
├── Small fixed size (<20) → [Item!]!
└── Variable/large size → ItemConnection!
Mutation result?
├── Can have user errors → Payload pattern
└── System errors only → Direct return
Multiple possible types?
├── Completely different → Union
└── Share common fields → Interface
Nested data?
├── Always needed together → Embed
└── Sometimes needed → Separate + ID reference
type User {
# Always required
id: ID!
email: String!
# Optional (user choice)
nickname: String
bio: String
# Lists: require list, require items
posts: [Post!]! # Never null, items never null
# Computed (may fail)
avatar: String # Nullable if generation can fail
}
| Issue | Cause | Solution |
|---|---|---|
| Breaking change | Removed field | Use @deprecated first |
| Over-fetching | No pagination | Add Connection pattern |
| N+1 queries | Direct relations | Use DataLoader |
| Type explosion | Too many types | Use interfaces/generics |
# Validate
npx graphql-inspector validate schema.graphql
# Check breaking changes
npx graphql-inspector diff old.graphql new.graphql
# Coverage analysis
npx graphql-inspector coverage schema.graphql queries/*.graphql
Skill("graphql-schema-design")
graphql-fundamentals - Basic types and syntaxgraphql-resolvers - Implementing the schemagraphql-security - Auth-aware design02-graphql-schema - For detailed guidance