plugin

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package plugin defines the core contracts shared by the CLI, core orchestration, and the compiled-in plugins: the Plugin/Preset interfaces and the config types (mirroring @graphql-codegen/plugin-helpers' Types namespace).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Names

func Names() string

Names returns the sorted list of registered plugin names.

func PresetNames

func PresetNames() string

PresetNames returns the sorted list of registered preset names.

func Register

func Register(p Plugin)

Register adds a plugin to the registry (called from plugin packages' init()).

func RegisterPreset

func RegisterPreset(p OutputPreset)

RegisterPreset adds a preset to the registry (called from preset packages' init()).

Types

type Config

type Config struct {
	Schema                    any            `yaml:"schema" json:"schema"`
	Documents                 any            `yaml:"documents" json:"documents"`
	ExternalDocuments         any            `yaml:"externalDocuments" json:"externalDocuments"`
	Generates                 map[string]any `yaml:"generates" json:"generates"`
	Config                    ConfigMap      `yaml:"config" json:"config"`
	Require                   any            `yaml:"require" json:"require"`
	Overwrite                 *bool          `yaml:"overwrite" json:"overwrite"`
	Watch                     any            `yaml:"watch" json:"watch"`
	Silent                    bool           `yaml:"silent" json:"silent"`
	ErrorsOnly                bool           `yaml:"errorsOnly" json:"errorsOnly"`
	Verbose                   bool           `yaml:"verbose" json:"verbose"`
	Debug                     bool           `yaml:"debug" json:"debug"`
	IgnoreNoDocuments         bool           `yaml:"ignoreNoDocuments" json:"ignoreNoDocuments"`
	AllowPartialOutputs       bool           `yaml:"allowPartialOutputs" json:"allowPartialOutputs"`
	EmitLegacyCommonJSImports *bool          `yaml:"emitLegacyCommonJSImports" json:"emitLegacyCommonJSImports"`
	ImportExtension           string         `yaml:"importExtension" json:"importExtension"`
	SkipDocumentsValidation   any            `yaml:"skipDocumentsValidation" json:"skipDocumentsValidation"`
	Hooks                     ConfigMap      `yaml:"hooks" json:"hooks"`

	// cwd / filepath are set by the CLI after loading, not from the file.
	Cwd      string `yaml:"-" json:"-"`
	FilePath string `yaml:"-" json:"-"`
}

Config mirrors Types.Config from plugin-helpers. Polymorphic fields (schema, documents, externalDocuments) are kept as any and normalized at load time.

type ConfigMap

type ConfigMap = map[string]any

ConfigMap is a loosely-typed config object (mirrors JS PluginConfig).

type ConfiguredOutput

type ConfiguredOutput struct {
	Plugins            []ConfiguredPlugin
	Preset             string
	PresetConfig       ConfigMap
	Overwrite          *bool
	Documents          any
	ExternalDocuments  any
	Schema             any
	Config             ConfigMap
	Hooks              ConfigMap
	DocumentTransforms []any
	WatchPattern       any
}

ConfiguredOutput mirrors Types.ConfiguredOutput.

type ConfiguredPlugin

type ConfiguredPlugin struct {
	Name   string
	Config ConfigMap
}

ConfiguredPlugin is a single plugin entry: name -> config (mirrors Types.ConfiguredPlugin).

type DocumentFile

type DocumentFile struct {
	Location string
	Document *ast.QueryDocument
	RawSDL   string
	Hash     string
	Type     string // "standard" | "external"
}

DocumentFile is a parsed GraphQL document plus provenance metadata. (mirrors Types.DocumentFile).

type FileOutput

type FileOutput struct {
	Filename string
	Content  string
	Hooks    ConfigMap
}

FileOutput mirrors Types.FileOutput.

type GenerateOptions

type GenerateOptions struct {
	Filename                  string
	Plugins                   []ConfiguredPlugin
	Schema                    *ast.Schema
	Documents                 []*DocumentFile
	Config                    ConfigMap
	PluginMap                 map[string]Plugin
	PresetConfig              ConfigMap
	SkipDocumentsValidation   any
	PluginContext             ConfigMap
	EmitLegacyCommonJSImports *bool
	ImportExtension           string
}

GenerateOptions mirrors Types.GenerateOptions — the arguments the core orchestration passes to a plugin chain for a single output file.

type Output

type Output struct {
	Content string
	Prepend []string
	Append  []string
}

Output is a plugin's generated result (mirrors Types.PluginOutput: a string, or a { content, prepend, append } object).

func StringContent

func StringContent(s string) *Output

StringContent builds a plain string Output from content.

type OutputPreset

type OutputPreset interface {
	Name() string
	// BuildGeneratesSection mirrors the preset's buildGeneratesSection(options):
	// it receives the resolved GenerateOptions for the `generates` entry and
	// returns the expanded list of outputs to generate. options.Filename is the
	// baseOutputDir for the preset.
	BuildGeneratesSection(options *GenerateOptions) ([]GenerateOptions, error)
}

OutputPreset mirrors Types.OutputPreset: it fans a single `generates` entry out into multiple GenerateOptions (e.g. near-operation-file, client).

func GetPresetByName

func GetPresetByName(name string) (OutputPreset, error)

GetPresetByName resolves a preset by its short name (e.g. "client").

type Plugin

type Plugin interface {
	// Name is the registry key, e.g. "typescript", "add", "schema-ast".
	Name() string
	// Generate returns the emitted code for this plugin. Content is the main
	// body; Prepend/Append are hoisted before/after all plugins' content
	// (mirrors graphql-codegen's complex plugin output).
	Generate(schema *ast.Schema, docs []*DocumentFile, cfg ConfigMap, info *PluginInfo) (*Output, error)
}

Plugin is the Go equivalent of CodegenPlugin. Each plugin emits a chunk of code given the resolved schema, the operation documents, and its config.

func GetByName

func GetByName(name string) (Plugin, error)

GetByName resolves a plugin by its short name (e.g. "typescript", "add"). The JS version tries many npm package name variants; we resolve directly.

type PluginInfo

type PluginInfo struct {
	OutputFile    string
	AllPlugins    []ConfiguredPlugin
	PluginContext ConfigMap
}

PluginInfo is passed to Plugin.Generate (mirrors the `info` object in execute-plugin.ts).

type Validator

type Validator interface {
	// allPlugins is the full configured plugin list for the output (mirrors the
	// JS validate signature, which some plugins use to assert "only plugin").
	Validate(schema *ast.Schema, docs []*DocumentFile, cfg ConfigMap, outputFile string, allPlugins []ConfiguredPlugin) error
}

Validator is an optional interface a Plugin may implement. When present, the core calls Validate before Generate and aborts the output on error.

Jump to

Keyboard shortcuts

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