codegen

package
v0.8.6 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2022 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(cfg Config) error

func GenerateCode added in v0.8.6

func GenerateCode(data *Data) error

func GenerateServer

func GenerateServer(cfg Config, filename string) error

Types

type ArgSet added in v0.8.6

type ArgSet struct {
	Args     []*FieldArgument
	FuncDecl string
}

type Config

type Config struct {
	SchemaFilename SchemaFilenames   `yaml:"schema,omitempty"`
	SchemaStr      map[string]string `yaml:"-"`
	Exec           PackageConfig     `yaml:"exec"`
	Model          PackageConfig     `yaml:"model"`
	Resolver       PackageConfig     `yaml:"resolver,omitempty"`
	Models         TypeMap           `yaml:"models,omitempty"`
	StructTag      string            `yaml:"struct_tag,omitempty"`

	FilePath string `yaml:"-"`
	// contains filtered or unexported fields
}

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 (*Config) Check

func (cfg *Config) Check() error

type Data added in v0.8.6

type Data struct {
	Config          *config.Config
	Schema          *ast.Schema
	SchemaStr       map[string]string
	Directives      map[string]*Directive
	Objects         Objects
	Inputs          Objects
	Interfaces      map[string]*Interface
	ReferencedTypes map[string]*config.TypeReference

	QueryRoot        *Object
	MutationRoot     *Object
	SubscriptionRoot *Object
}

Data is a unified model of the code to be generated. Plugins may modify this structure to do things like implement resolvers or directives automatically (eg grpc, validation)

func BuildData added in v0.8.6

func BuildData(cfg *config.Config) (*Data, error)

func (*Data) Args added in v0.8.6

func (a *Data) Args() map[string][]*FieldArgument

type Directive

type Directive struct {
	Name string
	Args []*FieldArgument
}

func (*Directive) ArgsFunc added in v0.5.1

func (d *Directive) ArgsFunc() string

func (*Directive) CallArgs

func (d *Directive) CallArgs() string

func (*Directive) Declaration

func (d *Directive) Declaration() string

func (*Directive) ResolveArgs added in v0.8.6

func (d *Directive) ResolveArgs(obj string, next string) string

type Enum

type Enum struct {
	*NamedType
	Description string
	Values      []EnumValue
}

type EnumValue

type EnumValue struct {
	Name        string
	Description string
}

type Field

type Field struct {
	*ast.FieldDefinition

	TypeReference    *config.TypeReference
	GoFieldType      GoFieldType      // The field type in go, if any
	GoReceiverName   string           // The name of method & var receiver in go, if any
	GoFieldName      string           // The name of the method or var in go, if any
	IsResolver       bool             // Does this field need a resolver
	Args             []*FieldArgument // A list of arguments to be passed to this field
	MethodHasContext bool             // If this is bound to a go method, does the method also take a context
	NoErr            bool             // If this is bound to a go method, does that method have an error as the second argument
	Object           *Object          // A link back to the parent object
	Default          interface{}      // The default value
	Directives       []*Directive
}

func (*Field) ArgsFunc added in v0.5.1

func (f *Field) ArgsFunc() string

func (*Field) CallArgs

func (f *Field) CallArgs() string

func (*Field) ComplexityArgs added in v0.5.0

func (f *Field) ComplexityArgs() string

func (*Field) ComplexitySignature added in v0.5.0

func (f *Field) ComplexitySignature() string

func (*Field) GoNameUnexported

func (f *Field) GoNameUnexported() string

func (*Field) HasDirectives added in v0.8.6

func (f *Field) HasDirectives() bool

func (*Field) IsConcurrent

func (f *Field) IsConcurrent() bool

func (*Field) IsMethod

func (f *Field) IsMethod() bool

func (*Field) IsReserved added in v0.5.0

func (f *Field) IsReserved() bool

func (*Field) IsVariable

func (f *Field) IsVariable() bool

func (*Field) ResolverType

func (f *Field) ResolverType() string

func (*Field) ShortInvocation

func (f *Field) ShortInvocation() string

func (*Field) ShortResolverDeclaration

func (f *Field) ShortResolverDeclaration() string

type FieldArgument

type FieldArgument struct {
	*ast.ArgumentDefinition
	TypeReference *config.TypeReference
	VarName       string      // The name of the var in go
	Object        *Object     // A link back to the parent object
	Default       interface{} // The default value
	Directives    []*Directive
	Value         interface{} // value set in Data
}

func (*FieldArgument) Stream

func (f *FieldArgument) Stream() bool

type GoFieldType

type GoFieldType int
const (
	GoFieldUndefined GoFieldType = iota
	GoFieldMethod
	GoFieldVariable
)

type Interface

type Interface struct {
	*ast.Definition
	Type         types.Type
	Implementors []InterfaceImplementor
	InTypemap    bool
}

type InterfaceImplementor

type InterfaceImplementor struct {
	*ast.Definition

	Interface *Interface
	Type      types.Type
}

func (*InterfaceImplementor) ValueReceiver

func (i *InterfaceImplementor) ValueReceiver() bool

type Model

type Model struct {
	*NamedType
	Description string
	Fields      []ModelField
	Implements  []*NamedType
}

type ModelField

type ModelField struct {
	*Type
	GQLName     string
	GoFieldName string
	GoFKName    string
	GoFKType    string
	Description string
}

type Object

type Object struct {
	*ast.Definition

	Type               types.Type
	ResolverInterface  types.Type
	Root               bool
	Fields             []*Field
	Implements         []*ast.Definition
	DisableConcurrency bool
	Stream             bool
	Directives         []*Directive
}

func (*Object) Description added in v0.8.6

func (o *Object) Description() string

func (*Object) HasDirectives added in v0.8.6

func (o *Object) HasDirectives() bool

func (*Object) HasResolvers

func (o *Object) HasResolvers() bool

func (*Object) HasUnmarshal added in v0.8.6

func (o *Object) HasUnmarshal() bool

func (*Object) Implementors

func (o *Object) Implementors() string

func (*Object) IsConcurrent added in v0.5.0

func (o *Object) IsConcurrent() bool

func (*Object) IsReserved added in v0.5.0

func (o *Object) IsReserved() bool

type Objects

type Objects []*Object

func (Objects) ByName

func (os Objects) ByName(name string) *Object

type PackageConfig

type PackageConfig struct {
	Filename string `yaml:"filename,omitempty"`
	Package  string `yaml:"package,omitempty"`
	Type     string `yaml:"type,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

type SchemaFilenames added in v0.7.0

type SchemaFilenames []string

func (SchemaFilenames) Has added in v0.7.0

func (a SchemaFilenames) Has(file string) bool

func (*SchemaFilenames) UnmarshalYAML added in v0.7.0

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

type TypeMap

type TypeMap map[string]TypeMapEntry

func (TypeMap) Check

func (tm TypeMap) Check() error

func (TypeMap) Exists

func (tm TypeMap) Exists(typeName string) bool

type TypeMapEntry

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

type TypeMapField

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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