generator

package
v0.18.18 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	QueryStructName       = "Query"
	QueryStructClientName = "Client"
)

Variables

View Source
var ErrUnknownSDKLang = errors.New("unknown sdk language")

Functions

func GetSchema

func GetSchema() *introspection.Schema

func Overlay

func Overlay(ctx context.Context, overlay fs.FS, outputDir string) (rerr error)

func SetSchema

func SetSchema(schema *introspection.Schema)

func SetSchemaParents

func SetSchemaParents(schema *introspection.Schema)

SetSchemaParents sets all the parents for the fields.

Types

type ClientGeneratorConfig added in v0.18.15

type ClientGeneratorConfig struct {
	// The name of the module to generate for.
	ModuleName string

	// The list of all dependencies used by the module.
	// This is used by the client generator to automatically serves the
	// dependencies when connecting to the client.
	ModuleDependencies []ModuleSourceDependency

	// The directory where the client will be generated.
	ClientDir string
}

Specific configuration for client generation.

type CommonFunctions

type CommonFunctions struct {
	// contains filtered or unexported fields
}

CommonFunctions formatting function with global shared template functions.

func NewCommonFunctions

func NewCommonFunctions(schemaVersion string, formatTypeFuncs FormatTypeFuncs) *CommonFunctions

func (*CommonFunctions) CheckVersionCompatibility added in v0.12.0

func (c *CommonFunctions) CheckVersionCompatibility(minVersion string) bool

func (*CommonFunctions) ConvertID

func (c *CommonFunctions) ConvertID(f introspection.Field) bool

ConvertID returns true if the field returns an ID that should be converted into an object.

func (*CommonFunctions) FormatInputType

func (c *CommonFunctions) FormatInputType(r *introspection.TypeRef, scopes ...string) (string, error)

FormatInputType formats a GraphQL type into the SDK language input

Example: `String` -> `string`

func (*CommonFunctions) FormatOutputType

func (c *CommonFunctions) FormatOutputType(r *introspection.TypeRef, scopes ...string) (string, error)

FormatOutputType formats a GraphQL type into the SDK language output

Example: `String` -> `string`

func (*CommonFunctions) FormatReturnType

func (c *CommonFunctions) FormatReturnType(f introspection.Field, scopes ...string) (string, error)

FormatReturnType formats a GraphQL type into the SDK language output, unless it's an ID that will be converted which needs to be formatted as an input (for chaining).

func (*CommonFunctions) GetArrayField

func (c *CommonFunctions) GetArrayField(f *introspection.Field) ([]*introspection.Field, error)

func (*CommonFunctions) InnerType

func (*CommonFunctions) IsIDableObject

func (c *CommonFunctions) IsIDableObject(t *introspection.TypeRef) (bool, error)

func (*CommonFunctions) IsListOfEnum added in v0.18.13

func (c *CommonFunctions) IsListOfEnum(t *introspection.TypeRef) bool

func (*CommonFunctions) IsListOfObject

func (c *CommonFunctions) IsListOfObject(t *introspection.TypeRef) bool

func (*CommonFunctions) IsSelfChainable

func (c *CommonFunctions) IsSelfChainable(t introspection.Type) bool

IsSelfChainable returns true if an object type has any fields that return that same type.

func (*CommonFunctions) ObjectName

func (c *CommonFunctions) ObjectName(t *introspection.TypeRef) (string, error)

func (*CommonFunctions) ToLowerCase

func (c *CommonFunctions) ToLowerCase(s string) string

func (*CommonFunctions) ToUpperCase

func (c *CommonFunctions) ToUpperCase(s string) string

type Config

type Config struct {
	// Lang is the language to generate the module for.
	Lang SDKLang

	// OutputDir is the path to put the generated code.
	// Usually this is the path to the module source directory.
	// This allows generating extra file aside the client bindings
	// like go.mod, go.sum etc...
	OutputDir string

	// IntrospectionJSON is an optional pre-computed introspection json string.
	IntrospectionJSON string

	// A dagger client connected to the engine running the codegen.
	// This may be nil if the codegen is run outside of a dagger context and should
	// only be set if introspectionJSON or moduleSourceID are set.
	Dag *dagger.Client

	// Generate the client in bundle mode.
	Bundle bool

	// ModuleConfig is the specific config to generate module.
	ModuleConfig *ModuleGeneratorConfig

	// ClientConfig is the specific config to generate standalone client.
	ClientConfig *ClientGeneratorConfig
}

func (*Config) Close added in v0.18.15

func (c *Config) Close() error

Close existing dagger client if it exists. This is a convenience method to be used in the main codegen command using a defer.

type FormatTypeFuncs

type FormatTypeFuncs interface {
	WithScope(scope string) FormatTypeFuncs

	FormatKindList(representation string) string
	FormatKindScalarString(representation string) string
	FormatKindScalarInt(representation string) string
	FormatKindScalarFloat(representation string) string
	FormatKindScalarBoolean(representation string) string
	FormatKindScalarDefault(representation string, refName string, input bool) string
	FormatKindObject(representation string, refName string, input bool) string
	FormatKindInputObject(representation string, refName string, input bool) string
	FormatKindEnum(representation string, refName string) string
}

FormatTypeFuncs is an interface to format any GraphQL type. Each generator has to implement this interface.

type GeneratedState

type GeneratedState struct {
	// Overlay is the overlay filesystem that contains generated code to write
	// over the output directory.
	Overlay fs.FS

	// PostCommands are commands that need to be run after the codegen has
	// finished. This is used for example to run `go mod tidy` after generating
	// Go code.
	PostCommands []*exec.Cmd

	// NeedRegenerate indicates that the code needs to be generated again. This
	// can happen if the codegen spat out templates that depend on generated
	// types. In that case the codegen needs to be run again with both the
	// templates and the initially generated types available.
	NeedRegenerate bool
}

type Generator

type Generator interface {
	// GenerateModule runs codegen in a context of a module and returns a map of
	// default filename to content for that file.
	GenerateModule(ctx context.Context, schema *introspection.Schema, schemaVersion string) (*GeneratedState, error)

	// GenerateClient runs codegen in a context of a standalone client and returns
	// a map of default filename to content for that file.
	GenerateClient(ctx context.Context, schema *introspection.Schema, schemaVersion string) (*GeneratedState, error)

	// GenerateLibrary only generate the library bindings for the given schema.
	GenerateLibrary(ctx context.Context, schema *introspection.Schema, schemaVersion string) (*GeneratedState, error)
}

type ModuleGeneratorConfig added in v0.18.15

type ModuleGeneratorConfig struct {
	// Name of the module to generate code for.
	ModuleName string

	// ModuleSourcePath is the subpath in OutputDir where the module source subpath is located.
	ModuleSourcePath string

	// ModuleParentPath is the path from the module source subpath to the context directory
	ModuleParentPath string

	// Whether we are initializing a new module.
	// Currently, this is only used in go codegen to enforce backwards-compatible behavior
	// where a pre-existing go.mod file is checked during dagger init for whether its module
	// name is the expected value.
	IsInit bool
}

Specific configuration for module generation.

type ModuleSourceDependency added in v0.18.15

type ModuleSourceDependency struct {
	Kind   string
	Name   string `json:"moduleOriginalName"`
	Pin    string
	Source string `json:"asString"`
}

type SDKLang

type SDKLang string
const (
	SDKLangGo         SDKLang = "go"
	SDKLangTypeScript SDKLang = "typescript"
)

Directories

Path Synopsis
go
templates
Go name linting.
Go name linting.

Jump to

Keyboard shortcuts

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