Graphql expert

From seaworld008/Commonly-used-high-value-skills · View interactive version

Graphql expert is an AI agent skill from the GitHub repository seaworld008/Commonly-used-high-value-skills. Use when designing GraphQL APIs, reviewing schemas and resolvers, optimizing queries, managing federation, or checking GraphQL security and performance best practices.

How to use this skill

Skill file

GraphQL Expert

触发条件

核心能力

1. Schema 设计哲学 (Design Paradigms)

2. 高级查询与 Resolver 模式

3. 分页与数据导航 (Pagination)

4. 实时性与性能优化 (Performance & Real-time)

5. 安全性与认证授权 (Security & Auth)

常用命令/模板

Schema 定义模板 (SDL)

type User {
  id: ID!
  username: String!
  posts(first: Int, after: String): PostConnection! @auth(role: "USER")
}

type Query {
  me: User
  searchPosts(keyword: String!): [Post]
}

type Mutation {
  createPost(content: String!): Post
}

Resolver 实现示例 (DataLoader)

// 每次请求认证后构造 context。仓储按当前身份和租户过滤批查结果。
function createContext(viewer) {
  const user = new DataLoader(async keys => {
    const rows = await myDb.batchGetVisibleUsers(viewer, keys);
    const byId = new Map(rows.map(row => [row.id, row]));
    return keys.map(id => byId.get(id) ?? null);
  });
  return { viewer, loaders: { user } };
}

const resolvers = {
  Post: {
    author: (parent, args, context) => {
      return context.loaders.user.load(parent.authorId);
    }
  }
};

用两个权限不同的请求读取同一用户 ID,验证各自只得到本请求可见的结果。

查询示例

query GetMyProfile {
  me {
    id
    username
    posts(first: 10) {
      edges {
        node {
          title
          author {
            id
          }
        }
      }
    }
  }
}

边界与限制


注:本技能参考 Apollo GraphQL 和 GraphQL Foundation 官方推荐实践编写。

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.