config

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package config loads and validates .defederator.yml configuration files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Schema is the path to the Federation v2 supergraph SDL.
	// It is used both as the routing table and as the GraphQL schema for type generation.
	Schema string `yaml:"schema"`

	// Query lists glob patterns or explicit paths to .graphql operation files.
	Query []string `yaml:"query"`

	// Client configures the generated client Go file.
	Client PackageConfig `yaml:"client"`

	// Model optionally generates model types into a separate file.
	Model PackageConfig `yaml:"model,omitempty"`

	// SubgraphURLs overrides subgraph URLs at runtime.
	// Keys are join__Graph enum values (e.g. "PRODUCTS").
	SubgraphURLs map[string]string `yaml:"subgraph_urls,omitempty"`

	// Bindings maps GraphQL scalar names to Go types. Equivalent to genqlient's
	// bindings: section.
	Bindings map[string]TypeBinding `yaml:"bindings,omitempty"`

	// Generate controls optional generation behaviours.
	Generate *GenerateConfig `yaml:"generate,omitempty"`

	// URLMode controls how subgraph URLs appear in generated plan specs.
	// "baked" (default): URLs from the supergraph SDL are embedded in the
	// plan spec constants at generation time. NewClient takes only an *http.Client.
	// "enum": plan specs use subgraph enum names; URLs are provided at runtime.
	// NewClient takes an additional subgraphURLs map[string]string parameter.
	// Use "enum" when the supergraph SDL contains placeholder URLs (e.g. "unused").
	URLMode string `yaml:"url_mode,omitempty"`

	// Dir is the base directory for resolving relative paths (not serialised).
	Dir string `yaml:"-"`

	// Verbose enables per-file / per-operation progress diagnostics on stderr
	// during generation. Set by the CLI's --verbose flag; not serialised.
	Verbose bool `yaml:"-"`
}

Config is the top-level .defederator.yml structure.

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig reads and parses a .defederator.yml file. All relative paths inside the config are resolved relative to the file's directory.

func LoadConfigFromDir

func LoadConfigFromDir(dir string) (*Config, error)

LoadConfigFromDir searches dir and its parents for a config file. Defederator files take precedence over genqlient files. When a genqlient config is found, LoadGenqlientConfig is used so the field mapping is correct.

In both cases the returned Config is validated — callers can rely on Schema, Client.Filename, and Client.Package all being non-empty.

func LoadGenqlientConfig

func LoadGenqlientConfig(path string) (*Config, error)

LoadGenqlientConfig reads a genqlient.yaml file and converts it into a *Config suitable for defederator's generator. The SubgraphURLs field is left empty; callers must supply it via a sidecar .defederator.yml or a --subgraph-urls CLI flag.

func (*Config) ClientFilename

func (c *Config) ClientFilename() string

ClientFilename returns the absolute path for the generated client file.

func (*Config) SchemaPath

func (c *Config) SchemaPath() string

SchemaPath returns the absolute path to the supergraph SDL.

func (*Config) Validate

func (c *Config) Validate() error

Validate reports problems that would otherwise surface as obscure failures further down the pipeline. The check set intentionally errs on the side of "fail loudly at load time" — every condition here has previously caused a confusing downstream symptom.

type GenerateConfig

type GenerateConfig struct {
	ClientInterfaceName *string `yaml:"clientInterfaceName,omitempty"`
	// ExportOperations is a path to write a JSON manifest of all generated operations.
	// Empty means no manifest is written.
	ExportOperations string `yaml:"export_operations,omitempty"`
	// Optional controls how nullable GraphQL fields are represented in Go.
	// "pointer" (default): nullable T → *T; "value": nullable T → T (zero = absent).
	Optional string `yaml:"optional,omitempty"`
}

GenerateConfig controls optional code-generation behaviours.

type PackageConfig

type PackageConfig struct {
	Filename string `yaml:"filename"`
	Package  string `yaml:"package"`
}

PackageConfig specifies the output file and Go package name for generated code.

func (PackageConfig) IsDefined

func (p PackageConfig) IsDefined() bool

IsDefined returns true if both Filename and Package are set.

type TypeBinding

type TypeBinding struct {
	Type        string `yaml:"type"`
	Marshaler   string `yaml:"marshaler,omitempty"`
	Unmarshaler string `yaml:"unmarshaler,omitempty"`
}

TypeBinding maps a GraphQL scalar name to a Go type with optional custom marshal/unmarshal functions, matching genqlient's bindings: format.

Jump to

Keyboard shortcuts

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