Documentation
¶
Index ¶
- Constants
- Variables
- func GetSchema() *introspection.Schema
- func Introspect(ctx context.Context, dag *dagger.Client) (*introspection.Schema, string, error)
- func Overlay(ctx context.Context, logsW io.Writer, overlay fs.FS, outputDir string) (rerr error)
- func SetSchema(schema *introspection.Schema)
- func SetSchemaParents(schema *introspection.Schema)
- type CommonFunctions
- func (c *CommonFunctions) CheckVersionCompatibility(minVersion string) bool
- func (c *CommonFunctions) ConvertID(f introspection.Field) bool
- func (c *CommonFunctions) FormatInputType(r *introspection.TypeRef, scopes ...string) (string, error)
- func (c *CommonFunctions) FormatOutputType(r *introspection.TypeRef, scopes ...string) (string, error)
- func (c *CommonFunctions) FormatReturnType(f introspection.Field, scopes ...string) (string, error)
- func (c *CommonFunctions) GetArrayField(f *introspection.Field) ([]*introspection.Field, error)
- func (c *CommonFunctions) InnerType(t *introspection.TypeRef) *introspection.TypeRef
- func (c *CommonFunctions) IsIDableObject(t *introspection.TypeRef) (bool, error)
- func (c *CommonFunctions) IsListOfObject(t *introspection.TypeRef) bool
- func (c *CommonFunctions) IsSelfChainable(t introspection.Type) bool
- func (c *CommonFunctions) ObjectName(t *introspection.TypeRef) (string, error)
- func (c *CommonFunctions) ToLowerCase(s string) string
- func (c *CommonFunctions) ToUpperCase(s string) string
- type Config
- type FormatTypeFuncs
- type GeneratedState
- type Generator
- type SDKLang
Constants ¶
const ( QueryStructName = "Query" QueryStructClientName = "Client" )
Variables ¶
var ErrUnknownSDKLang = errors.New("unknown sdk language")
Functions ¶
func GetSchema ¶
func GetSchema() *introspection.Schema
func Introspect ¶
Introspect gets the Dagger Schema
func SetSchema ¶
func SetSchema(schema *introspection.Schema)
func SetSchemaParents ¶
func SetSchemaParents(schema *introspection.Schema)
SetSchemaParents sets all the parents for the fields.
Types ¶
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 (c *CommonFunctions) InnerType(t *introspection.TypeRef) *introspection.TypeRef
func (*CommonFunctions) IsIDableObject ¶
func (c *CommonFunctions) IsIDableObject(t *introspection.TypeRef) (bool, error)
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 supported by this codegen infra. Lang SDKLang // OutputDir is the path to place generated code. OutputDir string // ModuleName is the module name to generate code for. ModuleName string // ModuleSourcePath is the subpath in OutputDir where a the module source subpath is located. ModuleSourcePath string // ModuleParentPath is the path from the module source subpath to the context directory ModuleParentPath string // IntrospectionJSON is an optional pre-computed introspection json string. IntrospectionJSON string // Merge indicates whether to merge the module deps with the existing project (i.e. a go.mod in a *parent* directory). Merge bool // 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 // ClientOnly indicates that the codegen should only generate the client code. ClientOnly bool // Dev indicates that the codegen should use the local SDK instead of the published one. // This is only relevant when ClientOnly is true. Dev bool // The list of all dependencies used by the module. // This is used for client generator to automatically serves the dependencies // on connection. GitDependencies []modules.ModuleConfigDependency }
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) }