This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is the Native Data Connector (NDC) SDK for TypeScript, used to build Hasura data connectors. The SDK provides the server infrastructure, types, and utilities to implement the NDC Spec.
npm install # Install dependencies
npm run build # Compile TypeScript to dist/There are no tests configured in this repository (npm test exits with an error).
The NDC spec types are generated from Rust types in ndc-models. This requires Rust/Cargo:
npm run regenerate-schema # Runs typegen/regenerate-schema.shThis generates:
src/schema/schema.generated.json- JSON schema from Rust types viatypegen/src/main.rssrc/schema/schema.generated.ts- TypeScript types from JSON schemasrc/schema/version.generated.ts- VERSION and VERSION_HEADER_NAME constants
A patch file (src/schema/schema.generated.ts.patch) is automatically applied to fix type generation issues.
src/index.ts exports the start() function which is the main entry point for connector implementations. It uses Commander.js to parse CLI args and environment variables, then starts a Fastify server.
Connectors implement the Connector<Configuration, State> interface with these methods:
parseConfiguration(configurationDir)- Load and validate configurationtryInitState(configuration, metrics)- Initialize connector state and register Prometheus metricsgetCapabilities(configuration)- Return connector capabilities (synchronous)getSchema(configuration)- Return the connector's schemaquery(configuration, state, request)- Execute queriesmutation(configuration, state, request)- Execute mutationsqueryExplain/mutationExplain- Generate execution plansfetchMetrics(configuration, state)- Update metricsgetHealthReadiness(configuration, state)- Optional health check
Fastify-based HTTP server exposing NDC endpoints:
GET /capabilities- Returns version and capabilitiesGET /schema- Returns the schemaPOST /query- Execute queriesPOST /mutation- Execute mutationsPOST /query/explain,POST /mutation/explain- Explain endpointsGET /health,GET /metrics- Health and Prometheus metrics
The server handles authorization via HASURA_SERVICE_TOKEN_SECRET and validates NDC version compatibility via the X-Hasura-NDC-Version header.
ConnectorError is the base class. Convenience subclasses map to HTTP status codes:
BadRequest(400),Forbidden(403),Conflict(409),UnprocessableContent(422)InternalServerError(500),NotSupported(501),BadGateway(502)
OpenTelemetry is auto-initialized on SDK import. Supports GRPC and HTTP/protobuf protocols. Use withActiveSpan() to create user-visible spans.
Key environment variables:
OTEL_SERVICE_NAME,OTEL_EXPORTER_OTLP_ENDPOINT,OTEL_EXPORTER_OTLP_PROTOCOLHASURA_CONNECTOR_NAME,HASURA_CONNECTOR_VERSION
All NDC spec types are generated and exported from schema.generated.ts. The index.ts creates JSON schema wrappers used by Fastify for request/response validation.
- Avoid
anytypes - Use proper TypeScript types instead ofany. Leverage the generated types fromsrc/schema/schema.generated.tsfor NDC spec types. Create properly typed functions rather than using type casts withany.
Environment variables / CLI options for connector servers:
HASURA_CONFIGURATION_DIRECTORY/--configuration(required)HASURA_CONNECTOR_HOST/--host(default: "::")HASURA_CONNECTOR_PORT/--port(default: 8080)HASURA_SERVICE_TOKEN_SECRET/--service-token-secretHASURA_LOG_LEVEL/--log-level(default: "info")HASURA_PRETTY_PRINT_LOGS/--pretty-print-logs
Push a version tag (e.g., v8.2.0) that matches package.json version to trigger NPM publish via GitHub Actions. The release notes are read from CHANGELOG.md.