Documentation
¶
Index ¶
- func ClearInlineArgsMetadata()
- func ExpandInlineArguments(schema *ast.Schema) error
- func GenerateCode(data *Data) error
- func GenerateCodeIncremental(data *Data, opts IncrementalOptions) error
- func SerializeTransformedSchema(schema *ast.Schema, originalSources []*ast.Source) ([]*ast.Source, error)
- type ArgSet
- type AugmentedSource
- type Data
- type DependencyGraph
- type Directive
- func (d *Directive) ArgsFunc() string
- func (d *Directive) CallArgs() string
- func (d *Directive) CallName() string
- func (d *Directive) CallPath() string
- func (d *Directive) Declaration() string
- func (d *Directive) FunctionImpl() string
- func (d *Directive) IsBuiltIn() bool
- func (d *Directive) IsLocation(location ...ast.DirectiveLocation) bool
- func (d *Directive) ResolveArgs(obj string, next int) string
- type DirectiveList
- type Field
- func (f *Field) ArgsFunc() string
- func (f *Field) BatchCallArgs(parentVar string) string
- func (f *Field) CallArgs() string
- func (f *Field) ChildFieldContextFunc(name string) string
- func (f *Field) ComplexityArgs() string
- func (f *Field) ComplexitySignature() string
- func (f *Field) DirectiveObjName() string
- func (f *Field) FieldContextFunc() string
- func (f *Field) GoNameUnexported() string
- func (f *Field) GoResultName() (string, bool)
- func (f *Field) HasDirectives() bool
- func (f *Field) ImplDirectives() []*Directive
- func (f *Field) IsBatch() bool
- func (f *Field) IsConcurrent() bool
- func (f *Field) IsInputObject() bool
- func (f *Field) IsMap() bool
- func (f *Field) IsMethod() bool
- func (f *Field) IsReserved() bool
- func (f *Field) IsRoot() bool
- func (f *Field) IsVariable() bool
- func (f *Field) ResolverType() string
- func (f *Field) ShortBatchResolverDeclaration() string
- func (f *Field) ShortInvocation() string
- func (f *Field) ShortResolverDeclaration() string
- func (f *Field) ShortResolverSignature(ft *goast.FuncType) string
- func (f *Field) StubCallArgs() string
- type FieldArgument
- type GoFieldType
- type IncrementalOptions
- type InlineArgsInfo
- type Interface
- type InterfaceImplementor
- type Object
- func (o *Object) Description() string
- func (o *Object) HasDirectives() bool
- func (o *Object) HasField(name string) bool
- func (o *Object) HasResolvers() bool
- func (o *Object) HasUnmarshal() bool
- func (o *Object) Implementors() string
- func (o *Object) InputObjectDirectives() []*Directive
- func (o *Object) IsConcurrent() bool
- func (o *Object) IsMap() bool
- func (o *Object) IsReserved() bool
- func (o *Object) Reference() types.Type
- func (o *Object) UniqueFields() map[string][]*Field
- type Objects
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClearInlineArgsMetadata ¶ added in v0.17.84
func ClearInlineArgsMetadata()
ClearInlineArgsMetadata clears all stored metadata.
func ExpandInlineArguments ¶ added in v0.17.84
ExpandInlineArguments expands arguments marked with @inlineArguments and stores metadata for later codegen phase.
func GenerateCode ¶ added in v0.8.0
func GenerateCodeIncremental ¶ added in v0.17.88
func GenerateCodeIncremental(data *Data, opts IncrementalOptions) error
GenerateCodeIncremental generates code with content-based file writing. Files are only written if their content has changed, preserving mtimes for unchanged files and allowing Go's build cache to remain valid.
The changedSchemas parameter is used for logging purposes to show what triggered the regeneration. The actual optimization comes from the content-based file writing in templates.write().
Types ¶
type ArgSet ¶ added in v0.8.0
type ArgSet struct {
Args []*FieldArgument
FuncDecl string
}
type AugmentedSource ¶ added in v0.17.6
type AugmentedSource struct {
// path relative to Config.Exec.Filename
RelativePath string
Embeddable bool
BuiltIn bool
Source string
}
AugmentedSource contains extra information about graphql schema files which is not known directly from the Config.Sources data
type Data ¶ added in v0.8.0
type Data struct {
Config *config.Config
Schema *ast.Schema
// If a schema is broken up into multiple Data instance, each representing part of the schema,
// AllDirectives should contain the directives for the entire schema. Directives() can
// then be used to get the directives that were defined in this Data instance's sources.
// If a single Data instance is used for the entire schema, AllDirectives and Directives()
// will be identical.
// AllDirectives should rarely be used directly.
AllDirectives DirectiveList
Objects Objects
Inputs Objects
Interfaces map[string]*Interface
ReferencedTypes map[string]*config.TypeReference
ComplexityRoots map[string]*Object
QueryRoot *Object
MutationRoot *Object
SubscriptionRoot *Object
AugmentedSources []AugmentedSource
Plugins []any
}
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 (*Data) Args ¶ added in v0.8.0
func (d *Data) Args() map[string][]*FieldArgument
func (*Data) BuiltInDirectives ¶ added in v0.17.54
func (d *Data) BuiltInDirectives() DirectiveList
Get only the directives which should have a statically provided definition
func (*Data) Directives ¶ added in v0.8.0
func (d *Data) Directives() DirectiveList
Get only the directives which are defined in the config's sources.
func (*Data) HasBatchResolverFields ¶ added in v0.17.87
func (*Data) HasEmbeddableSources ¶ added in v0.17.6
func (*Data) UserDirectives ¶ added in v0.17.54
func (d *Data) UserDirectives() DirectiveList
Get only the directives which should have a user provided definition on server instantiation
type DependencyGraph ¶ added in v0.17.88
type DependencyGraph struct {
// SchemaToTypes maps schema file path -> type names defined in that file
SchemaToTypes map[string][]string
// TypeToSchema maps type name -> schema file path where it's defined
TypeToSchema map[string]string
// TypeDependencies maps type name -> type names it references
TypeDependencies map[string][]string
// SchemaDependencies maps schema file -> schema files it depends on
SchemaDependencies map[string]map[string]bool
}
DependencyGraph tracks type definitions and their cross-schema dependencies. This enables incremental generation by computing which schemas are affected when a subset of schema files change.
func BuildDependencyGraph ¶ added in v0.17.88
func BuildDependencyGraph(schema *ast.Schema) *DependencyGraph
BuildDependencyGraph constructs a dependency graph from the parsed schema
func NewDependencyGraph ¶ added in v0.17.88
func NewDependencyGraph() *DependencyGraph
NewDependencyGraph creates a new empty dependency graph
func (*DependencyGraph) GetAffectedSchemas ¶ added in v0.17.88
func (g *DependencyGraph) GetAffectedSchemas(changedSchemas []string) []string
GetAffectedSchemas returns all schema files that need regeneration when the given schemas have changed. Computes transitive closure of dependencies.
func (*DependencyGraph) GetTypesForSchemas ¶ added in v0.17.88
func (g *DependencyGraph) GetTypesForSchemas(schemas []string) map[string]bool
GetTypesForSchemas returns all type names defined in the given schema files
type Directive ¶
type Directive struct {
*ast.DirectiveDefinition
Name string
Args []*FieldArgument
config.DirectiveConfig
}
func (*Directive) Declaration ¶
func (*Directive) FunctionImpl ¶ added in v0.17.54
func (*Directive) IsLocation ¶ added in v0.9.1
func (d *Directive) IsLocation(location ...ast.DirectiveLocation) bool
IsLocation check location directive
type DirectiveList ¶ added in v0.9.1
func (DirectiveList) LocationDirectives ¶ added in v0.9.1
func (dl DirectiveList) LocationDirectives(location string) DirectiveList
LocationDirectives filter directives by location
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
VOkFunc bool // If this is bound to a go method, is it of shape (any, bool)
Object *Object // A link back to the parent object
Default any // The default value
Stream bool // does this field return a channel?
Directives []*Directive
HasHaser bool // Whether a haser method is available (e.g., HasName())
HaserMethodName string // Name of the haser method
Batch bool // Enable batch resolver for this field
}
func (*Field) BatchCallArgs ¶ added in v0.17.87
BatchCallArgs returns a comma-separated list of resolver call arguments for batch resolvers.
func (*Field) ChildFieldContextFunc ¶ added in v0.17.3
func (*Field) ComplexityArgs ¶ added in v0.5.0
func (*Field) ComplexitySignature ¶ added in v0.5.0
func (*Field) DirectiveObjName ¶ added in v0.9.1
func (*Field) FieldContextFunc ¶ added in v0.17.3
func (*Field) GoNameUnexported ¶
func (*Field) GoResultName ¶ added in v0.17.25
func (*Field) HasDirectives ¶ added in v0.8.0
func (*Field) ImplDirectives ¶ added in v0.9.1
func (*Field) IsBatch ¶ added in v0.17.87
IsBatch returns true if this field has batch resolver enabled.
func (*Field) IsConcurrent ¶
func (*Field) IsInputObject ¶ added in v0.17.25
func (*Field) IsReserved ¶ added in v0.5.0
func (*Field) IsVariable ¶
func (*Field) ResolverType ¶
func (*Field) ShortBatchResolverDeclaration ¶ added in v0.17.87
ShortBatchResolverDeclaration returns the method signature for a batch resolver. Batch resolvers accept multiple parent objects and return results for all of them. For example, if the normal resolver is:
Posts(ctx context.Context, obj *User) ([]*Post, error)
The batch resolver would be:
Posts(ctx context.Context, objs []*User) ([][]*Post, error)
func (*Field) ShortInvocation ¶
func (*Field) ShortResolverDeclaration ¶
func (*Field) ShortResolverSignature ¶ added in v0.17.23
ShortResolverSignature is identical to ShortResolverDeclaration, but respects previous naming (return) conventions, if any.
func (*Field) StubCallArgs ¶ added in v0.17.84
StubCallArgs returns a comma-separated list of argument variable names for stub code.
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 any // The default value
Directives []*Directive
Value any // value set in Data
CallArgumentDirectivesWithNull bool
}
func (*FieldArgument) DirectiveObjName ¶ added in v0.9.1
func (f *FieldArgument) DirectiveObjName() string
func (*FieldArgument) ImplDirectives ¶ added in v0.9.1
func (f *FieldArgument) ImplDirectives() []*Directive
ImplDirectives get not SkipRuntime and location ARGUMENT_DEFINITION directive
func (*FieldArgument) Stream ¶
func (f *FieldArgument) Stream() bool
type GoFieldType ¶
type GoFieldType int
const ( GoFieldUndefined GoFieldType = iota GoFieldMethod GoFieldVariable GoFieldMap )
type IncrementalOptions ¶ added in v0.17.88
type IncrementalOptions struct {
// ChangedSchemas is the list of schema file paths that have changed.
// If empty, performs full generation.
ChangedSchemas []string
// Verbose enables detailed logging
Verbose bool
}
IncrementalOptions configures incremental generation
type InlineArgsInfo ¶ added in v0.17.84
type InlineArgsInfo struct {
OriginalArgName string
OriginalType string
OriginalASTType *ast.Type
GoType string
ExpandedArgs []string
}
InlineArgsInfo stores metadata about arguments that were inlined. Used during codegen to bundle expanded arguments back into a single resolver parameter.
func GetInlineArgsMetadata ¶ added in v0.17.84
func GetInlineArgsMetadata(typeName, fieldName string) *InlineArgsInfo
GetInlineArgsMetadata retrieves metadata for a given type and field.
type Interface ¶
type Interface struct {
*ast.Definition
Type types.Type
Implementors []InterfaceImplementor
InTypemap bool
}
type InterfaceImplementor ¶
type InterfaceImplementor struct {
*ast.Definition
Type types.Type
TakeRef bool
}
func (*InterfaceImplementor) CanBeNil ¶ added in v0.11.0
func (i *InterfaceImplementor) CanBeNil() bool
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
PointersInUnmarshalInput bool
}
func (*Object) Description ¶ added in v0.8.0
func (*Object) HasDirectives ¶ added in v0.8.0
func (*Object) HasResolvers ¶
func (*Object) HasUnmarshal ¶ added in v0.8.0
func (*Object) Implementors ¶
func (*Object) InputObjectDirectives ¶ added in v0.17.87
InputObjectDirectives returns directives that should be executed at the INPUT_OBJECT level. This is used for input types to execute @directives placed on the input object itself, after all fields have been unmarshaled. See: https://github.com/99designs/gqlgen/issues/2281