Skip to content

Commit

Permalink
feat: Embed template for root file generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Victoria committed Oct 7, 2024
1 parent 828f152 commit 38686f5
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions codegen/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import (
"embed"
"errors"
"fmt"
"os"
"path/filepath"
"runtime"
"strings"

"github.com/vektah/gqlparser/v2/ast"
Expand Down Expand Up @@ -129,24 +127,18 @@ func addBuild(filename string, p *ast.Position, data *Data, builds *map[string]*
}
}

// go:embed root_.gotpl

Check failure on line 130 in codegen/generate.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.22)

SA9009: ineffectual compiler directive due to extraneous space: "// go:embed root_.gotpl" (staticcheck)

Check failure on line 130 in codegen/generate.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.23)

SA9009: ineffectual compiler directive due to extraneous space: "// go:embed root_.gotpl" (staticcheck)
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,
Expand Down

0 comments on commit 38686f5

Please sign in to comment.