config

package
v0.15.2 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MapType       = types.NewMap(types.Typ[types.String], types.NewInterfaceType(nil, nil).Complete())
	InterfaceType = types.NewInterfaceType(nil, nil)
)
View Source
var ErrTypeNotFound = errors.New("unable to find type")

Functions

func CompleteConfig

func CompleteConfig(config *Config) error

CompleteConfig fills in the schema and other values to a config loaded from YAML.

func IsNilable

func IsNilable(t types.Type) bool

Types

type Binder

type Binder struct {
	References []*TypeReference
	SawInvalid bool
	// contains filtered or unexported fields
}

Binder connects graphql types to golang types using static analysis

func (*Binder) CopyModifiersFromAst

func (b *Binder) CopyModifiersFromAst(t *ast.Type, base types.Type) types.Type

func (*Binder) DefaultUserObject

func (b *Binder) DefaultUserObject(name string) (types.Type, error)

func (*Binder) FindObject

func (b *Binder) FindObject(pkgName string, typeName string) (types.Object, error)

func (*Binder) FindType

func (b *Binder) FindType(pkgName string, typeName string) (types.Type, error)

func (*Binder) FindTypeFromName

func (b *Binder) FindTypeFromName(name string) (types.Type, error)

func (*Binder) ObjectPosition

func (b *Binder) ObjectPosition(typ types.Object) token.Position

func (*Binder) PointerTo

func (b *Binder) PointerTo(ref *TypeReference) *TypeReference

func (*Binder) PushRef

func (b *Binder) PushRef(ret *TypeReference)

func (*Binder) TypePosition

func (b *Binder) TypePosition(typ types.Type) token.Position

func (*Binder) TypeReference

func (b *Binder) TypeReference(schemaType *ast.Type, bindTarget types.Type) (ret *TypeReference, err error)

type Config

type Config struct {
	SchemaFilename           StringList                 `yaml:"schema,omitempty"`
	Exec                     ExecConfig                 `yaml:"exec"`
	Model                    PackageConfig              `yaml:"model,omitempty"`
	Federation               PackageConfig              `yaml:"federation,omitempty"`
	Resolver                 ResolverConfig             `yaml:"resolver,omitempty"`
	AutoBind                 []string                   `yaml:"autobind"`
	Models                   TypeMap                    `yaml:"models,omitempty"`
	StructTag                string                     `yaml:"struct_tag,omitempty"`
	Directives               map[string]DirectiveConfig `yaml:"directives,omitempty"`
	OmitSliceElementPointers bool                       `yaml:"omit_slice_element_pointers,omitempty"`
	SkipValidation           bool                       `yaml:"skip_validation,omitempty"`
	SkipModTidy              bool                       `yaml:"skip_mod_tidy,omitempty"`
	Sources                  []*ast.Source              `yaml:"-"`
	Packages                 *code.Packages             `yaml:"-"`
	Schema                   *ast.Schema                `yaml:"-"`

	// Deprecated: use Federation instead. Will be removed next release
	Federated bool `yaml:"federated,omitempty"`
}

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig creates a copy of the default config

func LoadConfig

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

LoadConfig reads the gqlgen.yml config file

func LoadConfigFromDefaultLocations

func LoadConfigFromDefaultLocations() (*Config, error)

LoadConfigFromDefaultLocations 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 LoadDefaultConfig

func LoadDefaultConfig() (*Config, error)

LoadDefaultConfig loads the default config so that it is ready to be used

func (*Config) Init

func (c *Config) Init() error

func (*Config) LoadSchema

func (c *Config) LoadSchema() error

func (*Config) NewBinder

func (c *Config) NewBinder() *Binder

func (*Config) ReloadAllPackages

func (c *Config) ReloadAllPackages()

type DirectiveConfig

type DirectiveConfig struct {
	SkipRuntime bool `yaml:"skip_runtime"`
}

type ExecConfig

type ExecConfig struct {
	Package string     `yaml:"package,omitempty"`
	Layout  ExecLayout `yaml:"layout,omitempty"` // Default: single-file

	// Only for single-file layout:
	Filename string `yaml:"filename,omitempty"`

	// Only for follow-schema layout:
	FilenameTemplate string `yaml:"filename_template,omitempty"` // String template with {name} as placeholder for base name.
	DirName          string `yaml:"dir"`
}

func (*ExecConfig) Check

func (r *ExecConfig) Check() error

func (*ExecConfig) Dir

func (r *ExecConfig) Dir() string

func (*ExecConfig) ImportPath

func (r *ExecConfig) ImportPath() string

func (*ExecConfig) IsDefined

func (r *ExecConfig) IsDefined() bool

func (*ExecConfig) Pkg

func (r *ExecConfig) Pkg() *types.Package

type ExecLayout

type ExecLayout string
var (
	// Write all generated code to a single file.
	ExecLayoutSingleFile ExecLayout = "single-file"
	// Write generated code to a directory, generating one Go source file for each GraphQL schema file.
	ExecLayoutFollowSchema ExecLayout = "follow-schema"
)

type PackageConfig

type PackageConfig struct {
	Filename string `yaml:"filename,omitempty"`
	Package  string `yaml:"package,omitempty"`
}

func (*PackageConfig) Check

func (c *PackageConfig) Check() error

func (*PackageConfig) Dir

func (c *PackageConfig) Dir() string

func (*PackageConfig) ImportPath

func (c *PackageConfig) ImportPath() string

func (*PackageConfig) IsDefined

func (c *PackageConfig) IsDefined() bool

func (*PackageConfig) Pkg

func (c *PackageConfig) Pkg() *types.Package

type ResolverConfig

type ResolverConfig struct {
	Filename         string         `yaml:"filename,omitempty"`
	FilenameTemplate string         `yaml:"filename_template,omitempty"`
	Package          string         `yaml:"package,omitempty"`
	Type             string         `yaml:"type,omitempty"`
	Layout           ResolverLayout `yaml:"layout,omitempty"`
	DirName          string         `yaml:"dir"`
}

func (*ResolverConfig) Check

func (r *ResolverConfig) Check() error

func (*ResolverConfig) Dir

func (r *ResolverConfig) Dir() string

func (*ResolverConfig) ImportPath

func (r *ResolverConfig) ImportPath() string

func (*ResolverConfig) IsDefined

func (r *ResolverConfig) IsDefined() bool

func (*ResolverConfig) Pkg

func (r *ResolverConfig) Pkg() *types.Package

type ResolverLayout

type ResolverLayout string
var (
	LayoutSingleFile   ResolverLayout = "single-file"
	LayoutFollowSchema ResolverLayout = "follow-schema"
)

type StringList

type StringList []string

func (StringList) Has

func (a StringList) Has(file string) bool

func (*StringList) UnmarshalYAML

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

type TypeMap

type TypeMap map[string]TypeMapEntry

func (TypeMap) Add

func (tm TypeMap) Add(name string, goType string)

func (TypeMap) Check

func (tm TypeMap) Check() error

func (TypeMap) Exists

func (tm TypeMap) Exists(typeName string) bool

func (TypeMap) ReferencedPackages

func (tm TypeMap) ReferencedPackages() []string

func (TypeMap) UserDefined

func (tm TypeMap) UserDefined(typeName string) bool

type TypeMapEntry

type TypeMapEntry struct {
	Model  StringList              `yaml:"model"`
	Fields map[string]TypeMapField `yaml:"fields,omitempty"`
}

type TypeMapField

type TypeMapField struct {
	Resolver        bool   `yaml:"resolver"`
	FieldName       string `yaml:"fieldName"`
	GeneratedMethod string `yaml:"-"`
}

type TypeReference

type TypeReference struct {
	Definition  *ast.Definition
	GQL         *ast.Type
	GO          types.Type  // Type of the field being bound. Could be a pointer or a value type of Target.
	Target      types.Type  // The actual type that we know how to bind to. May require pointer juggling when traversing to fields.
	CastType    types.Type  // Before calling marshalling functions cast from/to this base type
	Marshaler   *types.Func // When using external marshalling functions this will point to the Marshal function
	Unmarshaler *types.Func // When using external marshalling functions this will point to the Unmarshal function
	IsMarshaler bool        // Does the type implement graphql.Marshaler and graphql.Unmarshaler
	IsContext   bool        // Is the Marshaler/Unmarshaller the context version; applies to either the method or interface variety.
}

TypeReference is used by args and field types. The Definition can refer to both input and output types.

func (*TypeReference) Elem

func (ref *TypeReference) Elem() *TypeReference

func (*TypeReference) IsNamed

func (t *TypeReference) IsNamed() bool

func (*TypeReference) IsNilable

func (t *TypeReference) IsNilable() bool

func (*TypeReference) IsPtr

func (t *TypeReference) IsPtr() bool

func (*TypeReference) IsPtrToPtr

func (t *TypeReference) IsPtrToPtr() bool

fix for https://github.com/golang/go/issues/31103 may make it possible to remove this (may still be useful)

func (*TypeReference) IsPtrToSlice

func (t *TypeReference) IsPtrToSlice() bool

func (*TypeReference) IsScalar

func (t *TypeReference) IsScalar() bool

func (*TypeReference) IsSlice

func (t *TypeReference) IsSlice() bool

func (*TypeReference) IsStruct

func (t *TypeReference) IsStruct() bool

func (*TypeReference) IsTargetNilable

func (t *TypeReference) IsTargetNilable() bool

func (*TypeReference) MarshalFunc

func (t *TypeReference) MarshalFunc() string

func (*TypeReference) UniquenessKey

func (t *TypeReference) UniquenessKey() string

func (*TypeReference) UnmarshalFunc

func (t *TypeReference) UnmarshalFunc() string

Jump to

Keyboard shortcuts

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