generate

package
v0.0.0-...-3ca42bb Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: MIT Imports: 34 Imported by: 0

Documentation

Overview

Package generate provides programmatic access to genqlient's functionality, and documentation of its configuration options. For general usage documentation, see the project GitHub.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(config *Config) (map[string][]byte, error)

Generate is the main programmatic entrypoint to genqlient, and generates and returns Go source code based on the given configuration.

See Config for more on creating a configuration. The return value is a map from filename to the generated file-content (e.g. Go source). Callers who don't want to manage reading and writing the files should call Main.

func Main

func Main()

Main is the command-line entrypoint to genqlient; it's equivalent to calling

go run github.com/Khan/genqlient

For lower-level control over genqlient's operation, see Generate.

Types

type Casing

type Casing struct {
	AllEnums CasingAlgorithm            `yaml:"all_enums"`
	Enums    map[string]CasingAlgorithm `yaml:"enums"`
}

Casing wraps the casing-related options, and is documented further in the genqlient.yaml docs.

type CasingAlgorithm

type CasingAlgorithm string

CasingAlgorithm represents a way that genqlient can handle casing, and is documented further in the genqlient.yaml docs.

const (
	CasingDefault CasingAlgorithm = "default"
	CasingRaw     CasingAlgorithm = "raw"
)

type Config

type Config struct {
	// The following fields are documented in the [genqlient.yaml docs].
	//
	// [genqlient.yaml docs]: https://github.com/Khan/genqlient/blob/main/docs/genqlient.yaml
	Schema              StringList              `yaml:"schema"`
	Operations          StringList              `yaml:"operations"`
	Generated           string                  `yaml:"generated"`
	Package             string                  `yaml:"package"`
	ExportOperations    string                  `yaml:"export_operations"`
	ContextType         string                  `yaml:"context_type"`
	ClientGetter        string                  `yaml:"client_getter"`
	Bindings            map[string]*TypeBinding `yaml:"bindings"`
	PackageBindings     []*PackageBinding       `yaml:"package_bindings"`
	Casing              Casing                  `yaml:"casing"`
	Optional            string                  `yaml:"optional"`
	OptionalGenericType string                  `yaml:"optional_generic_type"`
	StructReferences    bool                    `yaml:"use_struct_references"`
	Extensions          bool                    `yaml:"use_extensions"`
	// contains filtered or unexported fields
}

Config represents genqlient's configuration, generally read from genqlient.yaml.

Callers must call Config.ValidateAndFillDefaults before using the config.

func ReadAndValidateConfig

func ReadAndValidateConfig(filename string) (*Config, error)

ReadAndValidateConfig reads the configuration from the given file, validates it, and returns it.

func ReadAndValidateConfigFromDefaultLocations

func ReadAndValidateConfigFromDefaultLocations() (*Config, error)

ReadAndValidateConfigFromDefaultLocations looks for a config file in the current directory, and all parent directories walking up the tree. The closest config file will be returned.

func (*Config) ValidateAndFillDefaults

func (c *Config) ValidateAndFillDefaults(baseDir string) error

ValidateAndFillDefaults ensures that the configuration is valid, and fills in any options that were unspecified.

The argument is the directory relative to which paths will be interpreted, typically the directory of the config file.

type PackageBinding

type PackageBinding struct {
	Package string `yaml:"package"`
}

A PackageBinding represents a Go package for which genqlient will automatically generate TypeBinding values, and is documented further in the genqlient.yaml docs.

type StringList

type StringList []string

StringList provides yaml unmarshaler to accept both `string` and `[]string` as a valid type. Sourced from gqlgen.

func (*StringList) UnmarshalYAML

func (a *StringList) UnmarshalYAML(unmarshal func(interface{}) error) error

type TypeBinding

type TypeBinding struct {
	Type              string `yaml:"type"`
	ExpectExactFields string `yaml:"expect_exact_fields"`
	Marshaler         string `yaml:"marshaler"`
	Unmarshaler       string `yaml:"unmarshaler"`
}

A TypeBinding represents a Go type to which genqlient will bind a particular GraphQL type, and is documented further in the genqlient.yaml docs.

Jump to

Keyboard shortcuts

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