Skip to content

feat(cli): add JSON Schema for hive.json config file#8154

Open
peterphitran wants to merge 2 commits into
graphql-hive:mainfrom
peterphitran:feat/hive-json-schema
Open

feat(cli): add JSON Schema for hive.json config file#8154
peterphitran wants to merge 2 commits into
graphql-hive:mainfrom
peterphitran:feat/hive-json-schema

Conversation

@peterphitran

Copy link
Copy Markdown

Background

The Hive CLI reads its settings from a hive.json file, but there is no
machine-readable description of that file. Editors cannot autocomplete its keys
or flag typos, and an invalid config is only surfaced at runtime as CLI error
100 ("Invalid Config Error").

Issue #3010 asks for a JSON Schema for hive.json, served over HTTP, so the file
can be referenced via the $schema property to get autocompletion, inline
documentation, and validation while editing.

Description

This change affects the CLI @graphql-hive/cli only. No services, APIs, or the
client/agent are touched.

  • packages/libraries/cli/hive-config.schema.json (new): a draft-07 JSON Schema.
    It is an anyOf union of the three shapes the Config class actually accepts:
    • modern: registry / cdn objects with endpoint + accessToken
    • deprecated flat: registry as a string plus token
    • namespaced: a default key, or a named space selected by HIVE_SPACE,
      wrapping either of the above
      additionalProperties: false on the modern and legacy branches gives typo
      detection (for example registery or accesToken).
  • packages/libraries/cli/package.json: added the schema to the files
    allowlist so it ships with the published package, and added ajv as a
    devDependency for the test.
  • packages/libraries/cli/README.md: documented the $schema line in the
    "Config file (hive.json)" section.
  • packages/libraries/cli/src/helpers/config.ts: a short comment above
    ConfigModel / LegacyConfigModel reminding contributors to keep the schema
    in sync. The schema is hand-written to match the existing
    usage-report-v2.schema.json precedent and to avoid a zod-to-json-schema
    dependency.
  • packages/libraries/cli/hive.json: added a $schema line to the dev config as
    a usage example.
  • .changeset/: @graphql-hive/cli minor.

Usage

{
  "$schema": "https://raw.githubusercontent.com/graphql-hive/console/main/packages/libraries/cli/hive-config.schema.json",
  "registry": {
    "endpoint": "https://app.graphql-hive.com/graphql",
    "accessToken": "..."
  }
}

Testing

  • packages/libraries/cli/tests/hive-config.schema.spec.ts (new): compiles the
    shipped schema with ajv and runs 13 cases. It accepts all three valid shapes
    (each with and without a $schema line) plus an empty object, and rejects key
    typos and wrong value types.
  • I also ran the same fixtures through the real Config class and confirmed the
    schema accepts what the CLI honors for modern and namespaced configs, and that
    adding $schema does not break parsing (zod strips the unknown top-level key).

Open questions for maintainers

  1. $schema hosting URL: it currently points at the raw GitHub main file. If
    you prefer a stable or branded host (app domain, docs, or a CDN), it is a
    one-line change in three places (schema $id, README example, dev
    hive.json). I can also register hive.json with SchemaStore as a follow-up.
  2. While testing I noticed legacy flat configs
    ({ "registry": "<url>", "token": "..." }) resolve to no endpoint in the
    current CLI. In Config.read() the legacy cache is set, then
    ConfigModel.safeParse runs unconditionally and throws on the string
    registry, and the catch wipes the cache. This looks like an accidental
    regression from 7fafb0774. I kept legacyConfig in the schema as deprecated
    but intent-correct, and I am happy to fix read() in this PR or a separate one.
  3. Namespaced branch: keep the HIVE_SPACE / default support in the schema, or
    trim to the documented modern shape only?
  4. Dev hive.json: happy to drop the $schema line if you would rather not
    touch that file.

Checklist

  • Input validation
  • Testing

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a JSON Schema (hive-config.schema.json) for the hive.json configuration file, along with corresponding documentation, package updates, and validation tests using ajv. The feedback correctly identifies that the repository name in the schema URLs and $id is incorrectly specified as console instead of platform across several files, including the changeset, README, schema definition, configuration, and test suite.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.


```json
{
"$schema": "https://raw.githubusercontent.com/graphql-hive/console/main/packages/libraries/cli/hive-config.schema.json",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The repository name is platform, not console. Update the schema URL to use graphql-hive/platform.

Suggested change
"$schema": "https://raw.githubusercontent.com/graphql-hive/console/main/packages/libraries/cli/hive-config.schema.json",
"$schema": "https://raw.githubusercontent.com/graphql-hive/platform/main/packages/libraries/cli/hive-config.schema.json",


```json
{
"$schema": "https://raw.githubusercontent.com/graphql-hive/console/main/packages/libraries/cli/hive-config.schema.json",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The repository name is platform, not console. Update the schema URL to use graphql-hive/platform.

Suggested change
"$schema": "https://raw.githubusercontent.com/graphql-hive/console/main/packages/libraries/cli/hive-config.schema.json",
"$schema": "https://raw.githubusercontent.com/graphql-hive/platform/main/packages/libraries/cli/hive-config.schema.json",

@@ -0,0 +1,94 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://raw.githubusercontent.com/graphql-hive/console/main/packages/libraries/cli/hive-config.schema.json",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The repository name is platform, not console. Update the $id URL to use graphql-hive/platform.

Suggested change
"$id": "https://raw.githubusercontent.com/graphql-hive/console/main/packages/libraries/cli/hive-config.schema.json",
"$id": "https://raw.githubusercontent.com/graphql-hive/platform/main/packages/libraries/cli/hive-config.schema.json",

@@ -1,4 +1,5 @@
{
"$schema": "https://raw.githubusercontent.com/graphql-hive/console/main/packages/libraries/cli/hive-config.schema.json",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The repository name is platform, not console. Update the schema URL to use graphql-hive/platform.

Suggested change
"$schema": "https://raw.githubusercontent.com/graphql-hive/console/main/packages/libraries/cli/hive-config.schema.json",
"$schema": "https://raw.githubusercontent.com/graphql-hive/platform/main/packages/libraries/cli/hive-config.schema.json",

Comment on lines +17 to +18
const SCHEMA_URL =
'https://raw.githubusercontent.com/graphql-hive/console/main/packages/libraries/cli/hive-config.schema.json';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The repository name is platform, not console. Update the SCHEMA_URL to use graphql-hive/platform.

Suggested change
const SCHEMA_URL =
'https://raw.githubusercontent.com/graphql-hive/console/main/packages/libraries/cli/hive-config.schema.json';
const SCHEMA_URL =
'https://raw.githubusercontent.com/graphql-hive/platform/main/packages/libraries/cli/hive-config.schema.json';

@peterphitran peterphitran force-pushed the feat/hive-json-schema branch from ff81e5a to 4d61074 Compare June 17, 2026 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant