Open tv42 opened 5 years ago
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Bugs don't disappear just because time passes!
So don't use trimpath? gqlgen doesnt get shipped to your servers, its a tool used in your ci/dev environment.
We might start inlining templates again, but its trading off a lot of developer experience to fix your build environment.
Trimpath is a very nice default.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
bazel uses trimpath to achieve reproducible builds. We use gqlgen/api to generate code. And modelgen fails in locating templates. The following patch works for us.
diff -urN a/codegen/templates/templates.go b/codegen/templates/templates.go
--- a/codegen/templates/templates.go 2020-05-26 15:48:27.000000000 -0700
+++ b/codegen/templates/templates.go 2020-05-26 15:48:28.000000000 -0700
@@ -75,6 +75,12 @@
roots = append(roots, "template.gotpl")
} else {
// load all the templates in the directory
+ // In a bazel environment, that uses trimpath to achieve reproducible builds, template files are under ${runfiles}/__main__/${rootDir} and not {rootDir} during runtime
+ // Hence prefix RUN_PATH if set.
+ // Ex: bazel-out/host/bin/src/code/generate.runfiles/__main__/external/com_github_99designs_gqlgen/codegen
+ if runFilesPath := os.Getenv("RUN_PATH"); runFilesPath != "" {
+ rootDir = filepath.Join(runFilesPath, rootDir)
+ }
err := filepath.Walk(rootDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
Update:
Instead of patching gqlgen code, changing directory to the runtime path helped. No patch required in gqlgen.
but its trading off a lot of developer experience to fix your build environment.
How about using the embed feature introduced in Go 1.16?
What happened?
What did you expect?
Success, like without
-trimpath
:Minimal graphql.schema and models to reproduce
Just about anything, really.
versions
gqlgen version
?go version
?And obviously modules.
It seems gqlgen is using build-time paths to try to locate its template files, and trimpath confuses that. Perhaps the templates should be bundled into the executable.