Documentation
¶
Overview ¶
Package api wraps the Hadron GraphQL endpoint: a genqlient client for typed operations, a raw escape hatch for `hadron api`, and the mapping from transport/GraphQL errors to exit codes.
Index ¶
- Constants
- func CollectNodeBatch(ids []string, ...) ([]*gen.NodeBatchNodeBatchNodeBatchResultNodesNode, []string, error)
- func DocumentFromBatchNode(n *batchNode) *nodedoc.Document
- func Endpoint(serverURL string) string
- func MapError(err error) error
- func NewClient(serverURL, token string, httpClient *http.Client) (graphql.Client, error)
- type FindNodesPage
- type ListNode
- type RawResult
Constants ¶
const NodeBatchCap = 200
NodeBatchCap mirrors hadron-server's BATCH_READ_MAX_NODES (cor:api:040): a single nodeBatch call accepts at most 200 ids and fails loud above that, so bulk reads fan out in fixed-size chunks. The server also enforces a ~1 MB response cap that can return a partial page (truncated=true) with the spillover ids in `omitted`; CollectNodeBatch re-requests those.
Variables ¶
This section is empty.
Functions ¶
func CollectNodeBatch ¶ added in v0.2.0
func CollectNodeBatch( ids []string, fetch func([]string) (*gen.NodeBatchNodeBatchNodeBatchResult, error), ) ([]*gen.NodeBatchNodeBatchNodeBatchResultNodesNode, []string, error)
CollectNodeBatch fetches full nodes for ids in cap-sized chunks, re-queuing the spillover the server drops under its response-size cap. fetch is injected rather than calling gen.NodeBatch directly so the chunking/truncation loop is unit-testable without a server and so each caller controls the field projection. Returns the nodes (input order is not preserved across chunks), the union of ids the server reported unavailable, and the first error.
Shared by the whole-corpus fan-outs (`memory export`, `spec get --prefix`).
func DocumentFromBatchNode ¶ added in v0.3.0
DocumentFromBatchNode maps a bulk-read node into the neutral nodedoc.Document the markdown/JSON codecs consume. It is the single gen→Document mapping shared by `memory export` and `node export`. Type "" carries the server default (info), so it never serializes and a re-import defaults correctly. The projection only carries the memory id, not the URN, so callers that emit a standalone file resolve and set Document.MemoryURN themselves.
Types ¶
type FindNodesPage ¶ added in v0.5.0
FindNodesPage is the flattened result of one findNodes call: the hit nodes (hits[].node hoisted to a bare slice, the shape every old `nodes`/`nodeSearch` caller expects), plus the envelope's total and the degraded/reason notes that `spec find` surfaces on a vector-less memory. Nodes is always non-nil.
func FindNodes ¶ added in v0.5.0
func FindNodes( ctx context.Context, client graphql.Client, query *string, mode *gen.FindNodesMode, filter *gen.NodeFilter, sort *gen.NodeSort, limit, offset *int, ) (*FindNodesPage, error)
FindNodes runs the unified node search/list (cor:api:090) and flattens the hits[].node envelope into a bare node slice. Omit query for a filtered list in deterministic order (the old `nodes` semantics); pass query + mode to rank (the old `nodeSearch`). All args are optional; nil pointers are omitted from the wire so the server applies no constraint. The caller maps GraphQL errors through MapError as usual.
type ListNode ¶ added in v0.5.0
type ListNode = gen.FindNodesFindNodesFindNodesResultHitsNodeHitNode
ListNode is the shallow node projection the unified `findNodes` field returns under hits[].node — id/loc/name/type/tags/seq/isRunnable/updatedAt. Aliased here so callers don't spell the deeply-nested genqlient type name (and so a future projection change is a one-line edit), matching the batchNode alias pattern in nodedoc.go.
type RawResult ¶
type RawResult struct {
Body json.RawMessage
Errors []rawError
}
RawResult is the verbatim GraphQL response envelope.
func RawGraphQL ¶
func RawGraphQL(ctx context.Context, serverURL, token, query string, variables map[string]any, httpClient *http.Client) (*RawResult, error)
RawGraphQL posts an arbitrary query/mutation to the server and returns the raw response body. Used by `hadron api`. The returned error carries the mapped exit code when the response contains GraphQL errors.