{{ if and (not IsPartial) (not IsModuleCode) }}
// Code generated by dagger. DO NOT EDIT.

package dag

import (
	"context"
	"os"
	"sync"
	
	dagger "{{.PackageImport}}"
)

var client *dagger.Client
var clientMu sync.Mutex

func initClient() *dagger.Client {
	clientMu.Lock()
	defer clientMu.Unlock()

	if client == nil {
		var err error
		client, err = dagger.Connect(context.Background(), dagger.WithLogOutput(os.Stdout))
		if err != nil {
			panic(err)
		}
	}
	return client
}

// Close the engine connection
func Close() error {
	clientMu.Lock()
	defer clientMu.Unlock()

	var err error
	if client != nil {
		err = client.Close()
		client = nil
	}
	return err
}

{{ range .Types }}
{{ if eq .Kind "OBJECT" }}

{{- if eq .Name "Query" }}

{{ range $field := .Fields }}
{{ $field.Description | Comment }}
{{- if $field.IsDeprecated }}
//
{{ $field.DeprecationReason | FormatDeprecation }}
{{- end }}
{{ FieldFunction $field true "dagger" }} {
	client := initClient()
	return client.{{ .Name | FormatName }}(
		{{- if not $field.TypeRef.IsObject -}}
		ctx,
		{{- end -}}
		{{- range $arg := $field.Args -}}
		{{- if not $arg.TypeRef.IsOptional -}}
		{{ $arg.Name }},
		{{- end -}}
		{{- end -}}
		{{- if $field.Args.HasOptionals -}}
		opts...,
		{{- end -}}
	)
}

{{ end }}
{{- end }}
{{ end }}

{{ end }}
{{ end }}