generate

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: MIT Imports: 31 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 github.com/Desuuuu/genqlient.

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/Desuuuu/genqlient`. For lower-level control over genqlient's operation, see Generate.

Types

type Config

type Config struct {
	// The following fields are documented at:
	// https://github.com/Desuuuu/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"`
	StructReferences bool                    `yaml:"use_struct_references"`
	OptionalPointers bool                    `yaml:"optional_pointers"`
	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 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 StringList

type StringList []string

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

https://github.com/99designs/gqlgen/blob/1a0b19feff6f02d2af6631c9d847bc243f8ede39/codegen/config/config.go#L302-L329

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 at: https://github.com/Desuuuu/genqlient/blob/main/docs/genqlient.yaml

Jump to

Keyboard shortcuts

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