generate

package
v0.0.0-...-597fc9d Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2022 License: MIT Imports: 32 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/Paperspace/genqlient

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

Types

type Config

type Config struct {
	// The following fields are documented in the [genqlient.yaml docs].
	//
	// [genqlient.yaml docs]: https://github.com/Paperspace/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"`
	Optional         string                  `yaml:"optional"`
	StructReferences bool                    `yaml:"use_struct_references"`
	Extensions       bool                    `yaml:"use_extensions"`

	// Set to true to use features that aren't fully ready to use.
	//
	// This is primarily intended for genqlient's own tests.  These features
	// are likely BROKEN and come with NO EXPECTATION OF COMPATIBILITY.  Use
	// them at your own risk!
	AllowBrokenFeatures bool `yaml:"allow_broken_features"`
	// 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"`
	Alias             string `yaml:"alias"`
	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