用途:该技能用于在项目中配置 @data-client/graphql,以对接 GraphQL API。应在 data-client-setup 检测到 GraphQL 模式后应用。
安装:需同时安装核心包与 GraphQL 包,命令为 npm install @data-client/graphql(或 yarn add、pnpm add)。
主要能力:创建 GQLEndpoint 实例,配置认证与自定义选项。基础用法为在 src/api/gql.ts 中导出 new GQLEndpoint('/graphql')。支持通过 getHeaders 添加认证头(如从 localStorage 读取 token 并设置 Authorization: Bearer),也支持异步 getHeaders 用于 token 刷新。可通过继承 GQLEndpoint 并重写 fetchResponse 实现自定义错误处理,例如识别 UNAUTHENTICATED 错误并派发 auth:expired 事件。
定义查询与变更:使用 gql.query 和 gql.mutation 定义操作,并传入 schema(如 User、UserCollection 或 UserCollection.push)。组件中可配合 @data-client/react 的 useSuspense 与 useController 使用。
检测清单:扫描代码库中的 GraphQL 端点 URL(如 /graphql)、认证头、自定义头(API key、租户 ID)及错误解析模式。
后续步骤:应用 data-client-schema 定义 Entity 类,再应用 data-client-react 或 data-client-vue。
限制:资料未提供具体版本要求、兼容性、性能数据或收费信息。