@harnessio/react-ccm-graphql-client

中文文档
0.3.9发布于 2026/11/11MITTypeScriptCommonJS零依赖近 30 天下载 4.7万

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

中文使用文档
文档目录15 节
  1. 软件包结构
  2. 如何生成和构建
  3. 初始化客户端
  4. CCMGraphQLClientCallbacks
  5. 使用钩子
  6. UI平台整合计划
  7. 第1步——通过yalc(反应-api-客户端)构建并发布
  8. 步骤2 — 添加到平台 UI cacm app
  9. 步骤3——同时初始化客户端 CCMServiceAPIClient
  10. 步骤4——在组件中使用钩子
  11. 步骤5——重建后同步
  12. 步骤 6 – 在发布到 npm 时去除 yalc 链接
  13. 更新 Schema 或查询
  14. 版本
  15. 许可证

反应 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 + 查询中生成钩子 :

yarn generate

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

yarn build

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


初始化客户端

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

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 样式 :

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-客户端)构建并发布

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

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

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,将 GraphQL 客户端添加到 RIST 客户端旁边:

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——在组件中使用钩子

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——重建后同步

修改软件包时 :

# in packages/ccm-graphql-client:
yarn build && yalc push
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

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

许可证

麻省理工学院版权(c) 调理公司

版本与发布记录

@harnessio/react-ccm-graphql-client 共发布 11 个版本,首次发布于 2026/06/24;过去 12 个月发布了 11 个版本。

版本发布日期距今
0.3.9latest2026/11/116 天前
0.3.82026/10/071 个月前
0.3.72026/10/061 个月前
0.3.62026/10/061 个月前
0.3.52026/09/301 个月前
0.3.42026/09/072 个月前

关于 @harnessio/react-ccm-graphql-client 的常见问题

@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 和提交记录判断。