graphschema

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package graphschema defines the .knit/di-graph.json format written by knit gen.

The file records which providers and types every injector depends on. It is a stable, versioned output for external tools (e.g. test impact analysis); see docs/02_data_models.md §2 for the specification.

Index

Constants

View Source
const DefaultPath = ".knit/di-graph.json"

DefaultPath is the default location of the graph file relative to the module root.

View Source
const Version = "1.0"

Version is the schema version written to and accepted from di-graph.json.

Variables

This section is empty.

Functions

func Marshal

func Marshal(g *Graph) ([]byte, error)

Marshal encodes g as indented JSON terminated by a newline. The output is deterministic for a given g.

func WriteFile

func WriteFile(path string, g *Graph) error

WriteFile writes g to path, creating parent directories as needed.

Types

type Dependency

type Dependency struct {
	// PkgPath is the import path of the provider's package.
	PkgPath string `json:"pkg_path"`
	// PkgDir is the provider package directory relative to the module root
	// (e.g. "./internal/handler"), or empty for packages outside the module.
	PkgDir string `json:"pkg_dir"`
	// Type is the fully qualified type supplied to the graph.
	Type string `json:"type"`
	// Provider is the fully qualified provider function, e.g.
	// github.com/org/repo/internal/handler.NewUserHandler.
	Provider string `json:"provider"`
	// BoundFrom is the concrete type Type was bound from via wire.Bind, or
	// empty when Type is provided directly.
	BoundFrom string `json:"bound_from,omitempty"`
}

Dependency is one type supplied while building an injector.

type Graph

type Graph struct {
	// Version is the schema version; always Version when written by knit.
	Version string `json:"version"`
	// GeneratedAt is the RFC 3339 generation timestamp.
	GeneratedAt string `json:"generated_at"`
	// Injectors lists every generated injector, sorted by PkgPath then Name.
	Injectors []Injector `json:"injectors"`
}

Graph is the root document of di-graph.json.

func Decode

func Decode(r io.Reader) (*Graph, error)

Decode reads a graph from r and validates its version.

func ReadFile

func ReadFile(path string) (*Graph, error)

ReadFile reads and validates the graph stored at path.

type Injector

type Injector struct {
	// Name is the injector function name, e.g. InitializeUserHandler.
	Name string `json:"name"`
	// PkgPath is the import path of the package declaring the injector.
	PkgPath string `json:"pkg_path"`
	// RootType is the fully qualified type the injector returns.
	RootType string `json:"root_type"`
	// Dependencies lists every type built for the injector, sorted by Type
	// then Provider.
	Dependencies []Dependency `json:"dependencies"`
}

Injector is the dependency subgraph of one injector function.

Jump to

Keyboard shortcuts

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