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 ChildFieldType
- type Data
- func (d *Data) Args() map[string][]*FieldArgument
- func (d *Data) BuiltInDirectives() DirectiveList
- func (d *Data) Directives() DirectiveList
- func (d *Data) ECArg() string
- func (d *Data) ECDot() string
- func (d *Data) ECFuncParam() string
- func (d *Data) FuncReceiver() string
- func (d *Data) HasBatchResolverFields() bool
- func (d *Data) HasEmbeddableSources() bool
- func (d *Data) ImplDirectivesCtx(f ImplDirectivesField) ImplDirectivesContext
- func (d *Data) InputObjectImplDirectivesCtx(obj *Object, errVal string) ImplDirectivesContext
- func (d *Data) QueryDirectivesCtx(dl DirectiveList) QueryDirectivesContext
- func (d *Data) UniqueChildFieldTypes() []*ChildFieldType
- func (d *Data) UserDirectives() DirectiveList
- 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) ChildFieldContextTypeName() 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
- func (f *Field) ZeroVal() string
- type FieldArgument
- type GoFieldType
- type ImplDirectivesContext
- type ImplDirectivesField
- 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) InvalidsIncrement(fieldSetVar string) string
- 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
- type QueryDirectivesContext
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 ChildFieldType ¶ added in v0.17.90
type ChildFieldType struct {
TypeName string
Definition *ast.Definition
}
ChildFieldType represents a unique object type referenced as a return type from fields across all objects. Used to generate shared childFields_* functions that deduplicate the repeated switch statements in fieldContext_*.
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) ECArg ¶ added in v0.17.90
ECArg returns the ec argument at a generated call site.
function syntax: "ec, " receiver syntax: ""
func (*Data) ECDot ¶ added in v0.17.90
ECDot returns the call-site prefix for a generated function call.
function syntax: "" receiver syntax: "ec."
func (*Data) ECFuncParam ¶ added in v0.17.90
ECFuncParam returns the ec parameter in a generated function declaration.
function syntax: "ec *executionContext, " receiver syntax: ""
func (*Data) FuncReceiver ¶ added in v0.17.90
FuncReceiver returns the receiver clause for a generated function declaration.
function syntax: "" receiver syntax: "(ec *executionContext) "
func (*Data) HasBatchResolverFields ¶ added in v0.17.87
func (*Data) HasEmbeddableSources ¶ added in v0.17.6
func (*Data) ImplDirectivesCtx ¶ added in v0.17.90
func (d *Data) ImplDirectivesCtx(f ImplDirectivesField) ImplDirectivesContext
ImplDirectivesCtx returns a context for the implDirectives template suitable for field and argument directive processing (ErrVal="zeroVal", ErrWrap=false).
func (*Data) InputObjectImplDirectivesCtx ¶ added in v0.17.90
func (d *Data) InputObjectImplDirectivesCtx(obj *Object, errVal string) ImplDirectivesContext
InputObjectImplDirectivesCtx returns a context for the implDirectives template for INPUT_OBJECT-level directive processing. errVal is the Go variable name to return on error (e.g., "it" or "&it").
func (*Data) QueryDirectivesCtx ¶ added in v0.17.90
func (d *Data) QueryDirectivesCtx(dl DirectiveList) QueryDirectivesContext
QueryDirectivesCtx returns a context for the queryDirectives template.
func (*Data) UniqueChildFieldTypes ¶ added in v0.17.90
func (d *Data) UniqueChildFieldTypes() []*ChildFieldType
UniqueChildFieldTypes collects all unique OBJECT types that appear as return types from fields. Each type appears once, enabling generation of a shared childFields_* lookup function instead of inlining the switch in every fieldContext_* function.
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
ChildFieldContextFunc returns the fieldContext function name for a child field. Callers must ensure TypeReference and Definition are non-nil (guaranteed by the template rendering path, which only calls this for bound fields).
func (*Field) ChildFieldContextTypeName ¶ added in v0.17.90
ChildFieldContextTypeName returns the GraphQL type name that this field resolves to. Used by templates to reference shared childFields_* functions.
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
func (*FieldArgument) ZeroVal ¶ added in v0.17.90
func (f *FieldArgument) ZeroVal() string
ZeroVal returns the Go declaration for the typed zero value of this argument's type, suitable for use as an error-path return value inside a directive closure.
type GoFieldType ¶
type GoFieldType int
const ( GoFieldUndefined GoFieldType = iota GoFieldMethod GoFieldVariable GoFieldMap )
type ImplDirectivesContext ¶ added in v0.17.90
type ImplDirectivesContext struct {
Field ImplDirectivesField
Data *Data
ErrVal string
ErrWrap bool
}
ImplDirectivesContext is the typed context passed to the implDirectives template. ErrVal is the Go variable name to return on error ("zeroVal" for the standard case, or the partially-built struct variable for INPUT_OBJECT directives). ErrWrap controls whether the error is wrapped in graphql.ErrorOnPath(ctx, err).
func (ImplDirectivesContext) ErrReturn ¶ added in v0.17.90
func (c ImplDirectivesContext) ErrReturn(errExpr string) string
ErrReturn returns the Go statements for the error path inside a directive closure. When ErrWrap is true the error is wrapped in graphql.ErrorOnPath; when false the typed zero value is declared before the plain error return. errExpr is the Go error expression to return (e.g. "err" or `errors.New("not implemented")`).
type ImplDirectivesField ¶ added in v0.17.90
type ImplDirectivesField interface {
DirectiveObjName() string
ImplDirectives() []*Directive
ZeroVal() string
}
ImplDirectivesField is the subset of Field and FieldArgument needed by the implDirectives template.
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
func (*Object) InvalidsIncrement ¶ added in v0.17.90
InvalidsIncrement returns the Go statement that increments the invalids counter for this object's field set. Concurrent objects require atomic access; sequential objects use a plain increment.
func (*Object) IsConcurrent ¶ added in v0.5.0
func (*Object) IsReserved ¶ added in v0.5.0
func (*Object) UniqueFields ¶ added in v0.8.2
type QueryDirectivesContext ¶ added in v0.17.90
type QueryDirectivesContext struct {
DirectiveList DirectiveList
Data *Data
}
QueryDirectivesContext is the typed context passed to the queryDirectives template.