# @harnessio/react-ccm-graphql-client 中文文档

规范地址：https://npmcn.com/package/%40harnessio/react-ccm-graphql-client/

版本：0\.3\.9
npm 元数据更新时间：2026-11-16T17:37:15.732Z
中文译文更新时间：2026-11-17T10:18:04.481Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40harnessio/react-ccm-graphql-client
原文对照：https://npmcn.com/package/%40harnessio/react-ccm-graphql-client/?lang=original
项目主页：https://github.com/harness/react-api-client
源码仓库：https://github.com/harness/react-api-client

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：285 kB，11 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- peer 依赖：graphql 16\.14\.2，@tanstack/react-query 4\.20\.4
- 首次发布：2026-06-24T05:39:18.236Z
- 最新版本发布：2026-11-11T08:16:13.108Z
- 近 30 天下载量：47332（2026-10-18 至 2026-11-16，npm 官方下载统计）
- 已发布版本数：11（近 12 个月 11 个）

## 中文简介

与反应钩子结合的 Harness CCM GraphQL API

## 安装

```sh
npm install @harnessio/react-ccm-graphql-client
```

也可以使用：`pnpm add @harnessio/react-ccm-graphql-client`、`yarn add @harnessio/react-ccm-graphql-client`、`bun add @harnessio/react-ccm-graphql-client`

## README

# 反应 CCM 图QL 客户端( WIP)

**图QL - > GQL 语言**

**类型脚本 - > TS 翻译**

**图QL + TypeScript - > 图克l 编码**

此软件包将Harness CCM GraphQL API 显示为已键入 `@tanstack/react-query` 钩子,由使用 CCM GraphQL 方案生成 `@graphql-codegen/cli`。 。 。 .

这是一个 **伴侣到 `@harnessio/react-ccm-service-client`** ——该套件涵盖REST端点;此套件涵盖GraphQL端点(`/ccm/api/graphql`) (中文(简体) ).

* * *

## 软件包结构

```
packages/ccm-graphql-client/
├── schema.graphql          # CCM GraphQL schema (source of truth — update when schema changes)
├── queries/                # .gql query/mutation files (one per operation)
├── codegen.ts              # graphql-codegen config
├── package.json
├── tsconfig.json
└── src/
    ├── index.ts            # Exports CCMGraphQLClient class + all generated hooks
    ├── fetcher.ts          # Custom fetch implementation wired to CCMGraphQLClient config
    └── services/
        └── index.ts        # Auto-generated — DO NOT edit manually
```

* * *

## 如何生成和构建

**从 schema + 查询中生成钩子 :**

```bash
yarn generate
```

**完整构建( 基因+编译) :**

```bash
yarn build
```

> `src/services/index.ts` 是自动生成的。 永远不要手工编辑它——更新 `schema.graphql` 或者说 `.gql` 文件并重运行 `yarn generate`。 。 。 .

* * *

## 初始化客户端

在使用任何钩之前, 初始化 `CCMGraphQLClient` 应用程序启动时一次 :

```ts
import { CCMGraphQLClient } from '@harnessio/react-ccm-graphql-client'

new CCMGraphQLClient({
  urlInterceptor: (url) => window.getApiBaseUrl(`/ccm/api/${url}`),
  getRequestHeaders: () => ({
    'harness-account': accountId
  }),
  responseInterceptor: (response) => {
    if (response.status === 401) {
      on401Handler()
    }
    return response
  }
})
```

### `CCMGraphQLClientCallbacks`

| 外地 | 类型 | 需求 | 说明 |
| --- | --- | --- | --- |
| `urlInterceptor` | `(url: string) => string` | 对 | 接收 `"graphql"` 并返回完整端点 URL,包括账户查询参数 |
| `getRequestHeaders` | `() => Record<string, string>` | 对 | 在每个请求中添加返回页眉( 自动、 账户等) |
| `responseInterceptor` | `(response: Response) => Response` | 没有 | 每次答复后都打电话——用于401次处理 |

* * *

## 使用钩子

产生的钩子跟随 `@tanstack/react-query` 样式 :

```tsx
import { useFetchAllPerspectivesQuery } from '@harnessio/react-ccm-graphql-client'

const { data, isLoading, error } = useFetchAllPerspectivesQuery({
  folderId: props.defaultFolderId,
  pageNo: 0,
  pageSize: 100
})
```

所有可用的钩子由包根导出.

* * *

## UI平台整合计划

平台UI (`apps/cacm`) 已经使用 `@harnessio/react-ccm-service-client`。这些是添加 GraphQL 支持的步骤.

### 第1步——通过yalc(反应-api-客户端)构建并发布

```bash
cd packages/ccm-graphql-client
yarn install
yarn build
yalc publish
```

### 步骤2 — 添加到平台 UI cacm app

```bash
cd /path/to/platformUI
yalc add @harnessio/react-ccm-graphql-client
pnpm install
pnpm add graphql @tanstack/react-query  # if not already in cacm/package.json
```

### 步骤3——同时初始化客户端 `CCMServiceAPIClient`

单位 [`apps/cacm/src/init-client.ts`](https://npmcn.com/package/platformUI/apps/cacm/src/init-client.ts),将 GraphQL 客户端添加到 RIST 客户端旁边:

```ts
import { CCMServiceAPIClient } from '@harnessio/react-ccm-service-client'
import { CCMGraphQLClient } from '@harnessio/react-ccm-graphql-client'

export const useOpenApiClients = (accountId: string) => {
  if (!accountId) return

  new CCMServiceAPIClient({
    urlInterceptor(url) {
      return window.getApiBaseUrl(`/ccm/api${url}`)
    },
    requestInterceptor: getRequestInterceptor(accountId),
    responseInterceptor: handle401Response
  })

  new CCMGraphQLClient({
    urlInterceptor: (url) =>
      window.getApiBaseUrl(`/ccm/api/${url}?accountIdentifier=${accountId}&routingId=${accountId}`),
    getRequestHeaders: () => ({ 'harness-account': accountId }),
    responseInterceptor: handle401Response
  })
}
```

### 步骤4——在组件中使用钩子

```tsx
import { useFetchAllPerspectivesQuery } from '@harnessio/react-ccm-graphql-client'

export const PerspectiveList = () => {
  const { data, isLoading } = useFetchAllPerspectivesQuery({
    folderId: '',
    pageNo: 0,
    pageSize: 20,
    filters: [],
    sortCriteria: { sortOrder: 'ASCENDING', sortType: 'NAME' },
    searchKey: '',
    viewIds: []
  })

  if (isLoading) return <span>Loading...</span>
  return <pre>{JSON.stringify(data, null, 2)}</pre>
}
```

### 步骤5——重建后同步

修改软件包时 :

```bash
# in packages/ccm-graphql-client:
yarn build && yalc push
```

### 步骤 6 – 在发布到 npm 时去除 yalc 链接

```bash
cd /path/to/platformUI
yalc remove @harnessio/react-ccm-graphql-client
pnpm install
# add the real npm version to cacm/package.json
```

* * *

## 更新 Schema 或查询

1.  替换 `schema.graphql` 和CCM后端团队的最新消息
2.  添加/编辑 `.gql` 文件在 `queries/`
3.  运行 `yarn generate` 重新生成 `src/services/index.ts`
4.  运行 `yarn build` 要编译
5.  运行 `yalc push` 同步到本地测试的 UI 平台

* * *

## 版本

![@harnessio/react-ccm-graphql-client](https://img.shields.io/npm/v/@harnessio/react-ccm-graphql-client.svg?style=flat-square)

版本的由计划变化和查询添加所驱动. 不手动编辑 `src/services/index.ts`。 。 。 .

## 许可证

[麻省理工学院](https://npmcn.com/package/%40harnessio/react-ccm-graphql-client/LICENSE.md)版权(c) [调理公司](https://harness.io/)

## 常见问题

### @harnessio/react-ccm-graphql-client 是什么？

与反应钩子结合的 Harness CCM GraphQL API

### 如何安装 @harnessio/react-ccm-graphql-client？

在项目目录运行 npm install @harnessio/react-ccm-graphql-client，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：graphql（16\.14\.2）、@tanstack/react-query（4\.20\.4）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @harnessio/react-ccm-graphql-client 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @harnessio/react-ccm-graphql-client 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @harnessio/react-ccm-graphql-client 可以商用吗？

@harnessio/react-ccm-graphql-client 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @harnessio/react-ccm-graphql-client 的下载量有多少？

根据 npm 官方下载统计，@harnessio/react-ccm-graphql-client 在 2026/10/18 – 2026/11/16 这 30 天内被下载 47,332 次，日均约 1,578 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @harnessio/react-ccm-graphql-client 还在维护吗？

最新版本 0\.3\.9 发布于 2026/11/11（6 天前）；至今共发布 11 个版本，其中过去 12 个月发布了 11 个；首次发布于 2026/06/24。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

