@harnessio/react-ccm-graphql-client

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

Harness CCM GraphQL APIs integrated with react hooks

原始使用文档
文档目录15 节
  1. Package Structure
  2. How to Generate and Build
  3. Initializing the Client
  4. CCMGraphQLClientCallbacks
  5. Using Hooks
  6. Platform UI Integration Plan
  7. Step 1 — Build and publish via yalc (in react-api-client)
  8. Step 2 — Add to platform UI cacm app
  9. Step 3 — Initialize the client alongside CCMServiceAPIClient
  10. Step 4 — Use a hook in a component
  11. Step 5 — Sync after rebuilding
  12. Step 6 — Remove yalc link when publishing to npm
  13. Updating the Schema or Queries
  14. Versioning
  15. License

React CCM GraphQL Client (WIP)

GraphQL -> GQL

TypeScript -> TS

GraphQL + TypeScript -> graphql-codegen

This package exposes Harness CCM GraphQL APIs as typed @tanstack/react-query hooks, generated from the CCM GraphQL schema using @graphql-codegen/cli.

It is a companion to @harnessio/react-ccm-service-client — that package covers REST endpoints; this one covers the GraphQL endpoint (/ccm/api/graphql).


Package Structure

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

How to Generate and Build

Generate hooks from schema + queries:

yarn generate

Full build (generate + compile):

yarn build

src/services/index.ts is auto-generated. Never edit it by hand — update schema.graphql or .gql files and re-run yarn generate.


Initializing the Client

Before using any hook, initialize CCMGraphQLClient once at app startup:

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

FieldTypeRequiredDescription
urlInterceptor(url: string) => stringYesReceives "graphql" and must return the full endpoint URL including account query params
getRequestHeaders() => Record<string, string>YesReturns headers added to every request (auth, account, etc.)
responseInterceptor(response: Response) => ResponseNoCalled after every response — use for 401 handling

Using Hooks

Generated hooks follow the @tanstack/react-query pattern:

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

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

All available hooks are exported from the package root.


Platform UI Integration Plan

Platform UI (apps/cacm) already uses @harnessio/react-ccm-service-client. These are the steps to add GraphQL support.

Step 1 — Build and publish via yalc (in react-api-client)

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

Step 2 — Add to platform 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

Step 3 — Initialize the client alongside CCMServiceAPIClient

In apps/cacm/src/init-client.ts, add the GraphQL client init next to the existing REST client:

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
  })
}

Step 4 — Use a hook in a component

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>
}

Step 5 — Sync after rebuilding

When you make changes to the package:

# 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

Updating the Schema or Queries

  1. Replace schema.graphql with the latest from the CCM backend team
  2. Add/edit .gql files under queries/
  3. Run yarn generate to regenerate src/services/index.ts
  4. Run yarn build to compile
  5. Run yalc push to sync to platform UI for local testing

Versioning

@harnessio/react-ccm-graphql-client

Versioning is driven by schema changes and query additions. Do not manually edit src/services/index.ts.

License

MIT. Copyright(c) Harness Inc

版本与发布记录

@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 APIs integrated with react hooks

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