graphqlapi

package
v0.10.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package graphqlapi serves a read-only GraphQL view of Approach's discovered repositories and persisted Flow records.

The package owns three things: the per-request read model (source.go), the schema and its resolvers (schema.go), and the HTTP handler with its transport hardening (server.go, limits.go). It never mutates Flow state — no Mutation or Subscription root type exists, and the handler rejects any operation that is not a query.

Index

Constants

View Source
const (
	// GraphQLPath is the single query endpoint.
	GraphQLPath = "/graphql"
	// HealthPath is the unauthenticated liveness endpoint.
	HealthPath = "/healthz"

	// MaxRequestBytes bounds the request body.
	MaxRequestBytes = 64 << 10
)

Variables

This section is empty.

Functions

func NewServer

func NewServer(opts ServerOptions) (http.Handler, error)

NewServer builds the read-only GraphQL handler.

Types

type Flow

type Flow struct {
	Record   flowstore.FlowRecord
	RepoPath string
}

Flow pairs a persisted record with its normalized repo path, so repo linkage and the Repo.id it resolves against always agree.

type FlowSource

type FlowSource func() ([]flowstore.FlowRecord, error)

FlowSource returns every persisted Flow record, in the store's order (UpdatedAt descending). A typed partial-list error accompanies usable healthy records and is logged server-side; every other failure surfaces to clients as a sanitized GraphQL error.

type Repo

type Repo struct {
	Path        string
	DisplayName string
	IsBare      bool
	InScanRoot  bool
}

Repo is one repository in a snapshot. Entries come either from the scanner or from a Flow record that references a repo outside the scan root.

type RepoSource

type RepoSource func() ([]scanner.Repo, error)

RepoSource returns the repositories discovered under the configured scan root. A failure is non-fatal: the snapshot degrades to an empty scanned set and still serves flow-derived repos (a missing or mistyped scan root is the ordinary case, not an exceptional one).

type ServerOptions

type ServerOptions struct {
	// Repos and Flows are the read seams for one snapshot per request.
	Repos RepoSource
	Flows FlowSource

	// Token, when non-empty, is required on every /graphql request as either
	// `Authorization: Bearer <token>` or `X-Approach-Token`.
	//
	// When it is empty the handler falls back to a loopback Host allowlist.
	// That is an anti-DNS-rebinding measure for browsers, not an access
	// control — Host is client-supplied. Leaving Token empty is only safe on a
	// loopback bind, and enforcing that pairing is the caller's job;
	// cmd/approach/serve.go refuses to open a non-loopback listener without a
	// token.
	Token string

	// Logger receives one line per request plus sanitized failure detail. It
	// never receives the token or the query body.
	Logger io.Writer

	// RequestTimeout bounds how long a client waits for snapshot
	// construction. Zero means 20s. Package-level seam; not a CLI flag.
	RequestTimeout time.Duration

	// MaxInFlight caps concurrent snapshot construction. Zero means 8.
	// Package-level seam; not a CLI flag.
	MaxInFlight int
	// contains filtered or unexported fields
}

ServerOptions configures the GraphQL HTTP handler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL