diff --git a/codegen/generate.go b/codegen/generate.go index bbd4d9472e0..3d88b04581f 100644 --- a/codegen/generate.go +++ b/codegen/generate.go @@ -4,9 +4,7 @@ import ( "embed" "errors" "fmt" - "os" "path/filepath" - "runtime" "strings" "github.com/vektah/gqlparser/v2/ast" @@ -129,24 +127,18 @@ func addBuild(filename string, p *ast.Position, data *Data, builds *map[string]* } } +//go:embed root_.gotpl +var rootTemplate string + // Root file contains top-level definitions that should not be duplicated across the generated // files for each schema file. func generateRootFile(data *Data) error { dir := data.Config.Exec.DirName path := filepath.Join(dir, "root_.generated.go") - _, thisFile, _, _ := runtime.Caller(0) - rootDir := filepath.Dir(thisFile) - templatePath := filepath.Join(rootDir, "root_.gotpl") - templateBytes, err := os.ReadFile(templatePath) - if err != nil { - return err - } - template := string(templateBytes) - return templates.Render(templates.Options{ PackageName: data.Config.Exec.Package, - Template: template, + Template: rootTemplate, Filename: path, Data: data, RegionTags: false,