Help us shape the future of Go! Take the 2026 Go Developer Survey

generator

package
v0.44.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 20 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(ctx context.Context, cfg *config.Config) error

func GenerateAll added in v0.41.0

func GenerateAll(ctx context.Context, configDirs []string) error

GenerateAll runs Generate for every config directory, in order, in a single process, sharing gqlgen's package cache between them: the packages named in autobind and models are loaded and type checked once per run instead of once per config.

Each config is processed with the working directory set to the directory of its config file, so the paths in a config are relative to the config file. The cache is not safe for concurrent use, so the configs are processed serially; run several processes to use more cores.

The configs must belong to the same Go module, because the cache is keyed by import path and resolved through the module of the first config. gqlgen keeps the Go names it has chosen for GraphQL names for the whole process, so the configs should share one schema: with different schemas a GraphQL name whose Go name is already taken gets a numeric suffix that a separate run would not add. A package named in autobind or models must not import the output of another config of the same run, because only the output packages themselves are dropped from the cache when they are rewritten.

Arguments:

  • ctx: used for the remote schema introspection, if any
  • configDirs: the directories holding a config file; "." when empty. The config file is searched upward from each directory, like the -c flag. A config file given more than once is generated once

Returns:

  • error: the first failure. It is a *LoadConfigError when the config could not be found or loaded. When more than one directory is given, the message is prefixed with the directory so the failing config can be identified

Preconditions:

  • see above

Postconditions:

  • the working directory is restored before returning
  • a config is never started after an earlier one failed

Types

type LoadConfigError added in v0.41.0

type LoadConfigError struct {
	// ConfigDir is the directory given by the caller.
	ConfigDir string
	// Err is the underlying error.
	Err error
}

LoadConfigError is returned by GenerateAll when a config could not be found or loaded, as opposed to a failure while generating code from it.

func (*LoadConfigError) Error added in v0.41.0

func (e *LoadConfigError) Error() string

func (*LoadConfigError) Unwrap added in v0.41.0

func (e *LoadConfigError) Unwrap() error

Jump to

Keyboard shortcuts

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