Skip to content

feat(schema): port schema introspect from Go CLI#11

Draft
beengud wants to merge 2 commits into
mainfrom
feat/schema-introspect
Draft

feat(schema): port schema introspect from Go CLI#11
beengud wants to merge 2 commits into
mainfrom
feat/schema-introspect

Conversation

@beengud

@beengud beengud commented Jun 24, 2026

Copy link
Copy Markdown
Owner

Closes #8

Summary

Ports the schema introspect command from the deprecated Go Observe CLI (cmd_schema.go) into the TypeScript CLI.

observe schema introspect [--type <TypeName>]

  • Runs a GraphQL introspection query against the Observe /v1/meta endpoint and prints the result as formatted JSON.
  • --type <TypeName> filters the output to a single named type (e.g. Dashboard, DashboardInput, Mutation, Query), matching against __schema.types[].name client-side. Mirrors the Go --type filtering exactly, including the type "X" not found error + non-zero exit.
  • Gracefully handles the case where introspection is disabled on the tenant: the GraphQL error is detected and reported with a clear message plus exit code 1.

Implementation notes

  • This is a raw introspection query, not a codegen'd domain operation, so it does not depend on src/gql/generated/graphql.ts. The introspection query string replicates the exact query the Go CLI used (Schema_Introspect).
  • The fetch (src/gql/schema/introspect-schema.ts) mirrors the auth/header approach of executeGraphQL in src/gql/gql-request.ts (same Authorization: Bearer <customerId> <token> header, same observeApiHeaders, same /v1/meta URL and GqlApiError handling) but issues the raw query directly since there is no TypedDocumentNode to print().
  • The .graphql file (src/gql/schema/introspect-schema.graphql) is included for parity with the repo convention and is kept in sync with the inline query string.

Files added/changed

Added:

  • src/commands/schema/introspect.ts
  • src/commands/schema/index.ts
  • src/commands/schema/introspect.test.ts
  • src/gql/schema/introspect-schema.ts
  • src/gql/schema/introspect-schema.graphql

Changed:

  • src/app.ts — registered schema route (added before cli, which remains last)
  • README.md — added observe schema introspect to the Commands table (order matches src/app.ts)
  • AGENTS.md — added schema resource to the Project Structure section (commands + gql)

Verification status

  • Codegen / typecheck / full build could NOT run locally: GraphQL introspection is disabled on the available tenant, so bun run codegen cannot run and src/gql/generated/graphql.ts does not exist. This is expected; nothing under src/gql/generated/ was hand-written or committed. Note: this command itself does not import generated types, so it is unaffected by the missing codegen.
  • Runtime caveat: because introspection is disabled on the test tenant, this command cannot be runtime-verified here. It is implemented faithfully against the Go source so it will work on tenants where introspection is enabled, and it handles the introspection-disabled error gracefully (clear message + exit 1).
  • Unit tests run and passing: bun test src/commands/schema/introspect.test.ts -> 5 pass, 0 fail. Covers: full-schema JSON output, --type filtering to a single type, --type not-found exit-1, introspection-disabled message + exit-1, and generic API error exit-1. Tests mock the introspection fetch module via mock.module(...) before importing the command, so they run cleanly without codegen.

Assumptions / risks

  • The introspection query field set (fields, inputFields, enumValues, interfaces, possibleTypes, nested ofType two levels deep, includeDeprecated: true) is copied verbatim from the Go CLI and is standard GraphQL introspection, but could not be validated against a live schema since introspection is disabled.
  • Introspection-disabled detection matches GraphQL errors whose message contains "introspection" (case-insensitive). The exact server error wording could not be confirmed on the live tenant; if it differs, the command still exits 1 via the generic API Error path.

nhl-beengud and others added 2 commits June 24, 2026 09:11
Closes #8

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Parameters<introspect>[1] is the deps arg (not [2]); the prior index
produced two tsc errors. Caught via typecheck against the published
Observe schema setup.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Port schema introspect from the Go fork

2 participants