Documentation ¶
Index ¶
- Variables
- func CompleteConfig(config *Config) error
- func IsNilable(t types.Type) bool
- type Binder
- func (b *Binder) CopyModifiersFromAst(t *ast.Type, base types.Type) types.Type
- func (b *Binder) DefaultUserObject(name string) (types.Type, error)
- func (b *Binder) FindObject(pkgName, typeName string) (types.Object, error)
- func (b *Binder) FindType(pkgName, typeName string) (types.Type, error)
- func (b *Binder) FindTypeFromName(name string) (types.Type, error)
- func (b *Binder) InstantiateType(orig types.Type, targs []types.Type) (types.Type, error)
- func (b *Binder) ObjectPosition(typ types.Object) token.Position
- func (b *Binder) PointerTo(ref *TypeReference) *TypeReference
- func (b *Binder) PushRef(ret *TypeReference)
- func (b *Binder) TypePosition(typ types.Type) token.Position
- func (b *Binder) TypeReference(schemaType *ast.Type, bindTarget types.Type) (ret *TypeReference, err error)
- type Config
- type DirectiveConfig
- type EnumValue
- type EnumValueReference
- type ExecConfig
- type ExecLayout
- type GoInitialismsConfig
- type ModelExtraField
- type PackageConfig
- type ResolverConfig
- type ResolverLayout
- type StringList
- type TypeMap
- type TypeMapEntry
- type TypeMapField
- type TypeReference
- func (ref *TypeReference) Elem() *TypeReference
- func (ref *TypeReference) HasEnumValues() bool
- func (ref *TypeReference) IsMap() bool
- func (ref *TypeReference) IsNamed() bool
- func (ref *TypeReference) IsNilable() bool
- func (ref *TypeReference) IsPtr() bool
- func (ref *TypeReference) IsPtrToIntf() bool
- func (ref *TypeReference) IsPtrToPtr() bool
- func (ref *TypeReference) IsPtrToSlice() bool
- func (ref *TypeReference) IsScalar() bool
- func (ref *TypeReference) IsSlice() bool
- func (ref *TypeReference) IsStruct() bool
- func (ref *TypeReference) IsTargetNilable() bool
- func (ref *TypeReference) MarshalFunc() string
- func (ref *TypeReference) UniquenessKey() string
- func (ref *TypeReference) UnmarshalFunc() string
Constants ¶
This section is empty.
Variables ¶
var ( MapType = types.NewMap(types.Typ[types.String], types.NewInterfaceType(nil, nil).Complete()) InterfaceType = types.NewInterfaceType(nil, nil) )
var ErrTypeNotFound = errors.New("unable to find type")
Functions ¶
func CompleteConfig ¶
CompleteConfig fills in the schema and other values to a config loaded from YAML.
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 (*Binder) DefaultUserObject ¶
func (*Binder) FindObject ¶
func (*Binder) FindTypeFromName ¶
func (*Binder) InstantiateType ¶
func (*Binder) PointerTo ¶
func (b *Binder) PointerTo(ref *TypeReference) *TypeReference
func (*Binder) PushRef ¶
func (b *Binder) PushRef(ret *TypeReference)
func (*Binder) TypeReference ¶
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"` GoBuildTags StringList `yaml:"go_build_tags,omitempty"` GoInitialisms GoInitialismsConfig `yaml:"go_initialisms,omitempty"` OmitSliceElementPointers bool `yaml:"omit_slice_element_pointers,omitempty"` OmitGetters bool `yaml:"omit_getters,omitempty"` OmitInterfaceChecks bool `yaml:"omit_interface_checks,omitempty"` OmitComplexity bool `yaml:"omit_complexity,omitempty"` OmitGQLGenFileNotice bool `yaml:"omit_gqlgen_file_notice,omitempty"` OmitGQLGenVersionInFileNotice bool `yaml:"omit_gqlgen_version_in_file_notice,omitempty"` OmitRootModels bool `yaml:"omit_root_models,omitempty"` OmitResolverFields bool `yaml:"omit_resolver_fields,omitempty"` OmitPanicHandler bool `yaml:"omit_panic_handler,omitempty"` // If this is set to true, argument directives that // decorate a field with a null value will still be called. // // This enables argumment directives to not just mutate // argument values but to set them even if they're null. CallArgumentDirectivesWithNull bool `yaml:"call_argument_directives_with_null,omitempty"` StructFieldsAlwaysPointers bool `yaml:"struct_fields_always_pointers,omitempty"` ReturnPointersInUnmarshalInput bool `yaml:"return_pointers_in_unmarshalinput,omitempty"` ResolversAlwaysReturnPointers bool `yaml:"resolvers_always_return_pointers,omitempty"` NullableInputOmittable bool `yaml:"nullable_input_omittable,omitempty"` EnableModelJsonOmitemptyTag *bool `yaml:"enable_model_json_omitempty_tag,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 ¶
LoadConfig reads the gqlgen.yml config file
func LoadConfigFromDefaultLocations ¶
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 ¶
LoadDefaultConfig loads the default config so that it is ready to be used
func (*Config) LoadSchema ¶
func (*Config) ReloadAllPackages ¶
func (c *Config) ReloadAllPackages()
type DirectiveConfig ¶
type DirectiveConfig struct { SkipRuntime bool `yaml:"skip_runtime"` // If the directive implementation is statically defined, don't provide a hook for it // in the generated server. This is useful for directives that are implemented // by plugins or the runtime itself. // // The function implemmentation should be provided here as a string. // // The function should have the following signature: // func(ctx context.Context, obj any, next graphql.Resolver[, directive arguments if any]) (res any, err error) Implementation *string }
type EnumValueReference ¶
type EnumValueReference struct { Definition *ast.EnumValueDefinition Object types.Object }
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"` // Maximum number of goroutines in concurrency to use when running multiple child resolvers // Suppressing the number of goroutines generated can reduce memory consumption per request, // but processing time may increase due to the reduced number of concurrences // Default: 0 (unlimited) WorkerLimit uint `yaml:"worker_limit"` }
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 GoInitialismsConfig ¶
type GoInitialismsConfig struct { // If true, the Initialisms won't get appended to the default ones but replace them ReplaceDefaults bool `yaml:"replace_defaults"` // Custom initialisms to be added or to replace the default ones Initialisms []string `yaml:"initialisms"` }
GoInitialismsConfig allows to modify the default behavior of naming Go methods, types and properties
type ModelExtraField ¶
type ModelExtraField struct { // Type is the Go type of the field. // // It supports the builtin basic types (like string or int64), named types // (qualified by the full package path), pointers to those types (prefixed // with `*`), and slices of those types (prefixed with `[]`). // // For example, the following are valid types: // string // *github.com/author/package.Type // []string // []*github.com/author/package.Type // // Note that the type will be referenced from the generated/graphql, which // means the package it lives in must not reference the generated/graphql // package to avoid circular imports. // restrictions. Type string `yaml:"type"` // OverrideTags is an optional override of the Go field tag. OverrideTags string `yaml:"overrideTags"` // Description is an optional the Go field doc-comment. Description string `yaml:"description"` }
type PackageConfig ¶
type PackageConfig struct { Filename string `yaml:"filename,omitempty"` Package string `yaml:"package,omitempty"` Version int `yaml:"version,omitempty"` ModelTemplate string `yaml:"model_template,omitempty"` Options map[string]bool `yaml:"options,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"` OmitTemplateComment bool `yaml:"omit_template_comment,omitempty"` ResolverTemplate string `yaml:"resolver_template,omitempty"` PreserveResolver bool `yaml:"preserve_resolver,omitempty"` }
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(any) error) error
type TypeMap ¶
type TypeMap map[string]TypeMapEntry
func (TypeMap) ForceGenerate ¶
func (TypeMap) ReferencedPackages ¶
func (TypeMap) UserDefined ¶
type TypeMapEntry ¶
type TypeMapEntry struct { Model StringList `yaml:"model,omitempty"` ForceGenerate bool `yaml:"forceGenerate,omitempty"` Fields map[string]TypeMapField `yaml:"fields,omitempty"` EnumValues map[string]EnumValue `yaml:"enum_values,omitempty"` // Key is the Go name of the field. ExtraFields map[string]ModelExtraField `yaml:"extraFields,omitempty"` EmbedExtraFields []ModelExtraField `yaml:"embedExtraFields,omitempty"` }
type TypeMapField ¶
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 IsOmittable bool // Is the type wrapped with Omittable IsContext bool // Is the Marshaler/Unmarshaller the context version; applies to either the method or interface variety. PointersInUnmarshalInput bool // Inverse values and pointers in return. IsRoot bool // Is the type a root level definition such as Query, Mutation or Subscription EnumValues []EnumValueReference }
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) HasEnumValues ¶
func (ref *TypeReference) HasEnumValues() bool
func (*TypeReference) IsMap ¶
func (ref *TypeReference) IsMap() bool
func (*TypeReference) IsNamed ¶
func (ref *TypeReference) IsNamed() bool
func (*TypeReference) IsNilable ¶
func (ref *TypeReference) IsNilable() bool
func (*TypeReference) IsPtr ¶
func (ref *TypeReference) IsPtr() bool
func (*TypeReference) IsPtrToIntf ¶
func (ref *TypeReference) IsPtrToIntf() bool
func (*TypeReference) IsPtrToPtr ¶
func (ref *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 (ref *TypeReference) IsPtrToSlice() bool
func (*TypeReference) IsScalar ¶
func (ref *TypeReference) IsScalar() bool
func (*TypeReference) IsSlice ¶
func (ref *TypeReference) IsSlice() bool
func (*TypeReference) IsStruct ¶
func (ref *TypeReference) IsStruct() bool
func (*TypeReference) IsTargetNilable ¶
func (ref *TypeReference) IsTargetNilable() bool
func (*TypeReference) MarshalFunc ¶
func (ref *TypeReference) MarshalFunc() string
func (*TypeReference) UniquenessKey ¶
func (ref *TypeReference) UniquenessKey() string
func (*TypeReference) UnmarshalFunc ¶
func (ref *TypeReference) UnmarshalFunc() string