Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generated.go does not compile; undefined: gqlparser #1258

Closed
sateeshpnv opened this issue Jul 22, 2020 · 2 comments
Closed

generated.go does not compile; undefined: gqlparser #1258

sateeshpnv opened this issue Jul 22, 2020 · 2 comments

Comments

@sateeshpnv
Copy link
Contributor

What happened?

While migrating from v0.10.2 to v0.11.3, generated.go doesn't compile (It used to work absolutely fine under v0.10.2):

/private/var/tmp/_bazel_sateesh/.../sandbox/darwin-sandbox/1531/execroot/__main__/bazel-out/darwin-fastbuild/bin/src/.../generated.go:4521:20: undefined: gqlparser

generated.go does not import github.com/vektah/gqlparser/v2. However, generated!.gotpl region uses it - var parsedSchema = gqlparser.MustLoadSchema(sources...)

generated!.gotpl does have {{ reserveImport "github.com/vektah/gqlparser/v2" }}.

Looking through gqlgen code, there is code to prune - formatted, err := imports.Prune(filename, b, packages). config.Packages.packages does not have github.com/vektah/gqlparser/v2. Couldn't see why gqlparser/v2/ast is present in packages, but not gqlparser/v2.

What did you expect?

Expected generated.go to compile; to import the package that is indeed used in the generated!.gotpl region of the file.

Minimal graphql.schema and models to reproduce

versions

  • gqlgen version? v0.11.3
  • go version? v1.14.4
  • dep or go modules? go mod in a bazel project
@sateeshpnv
Copy link
Contributor Author

Suspected that there was an alias name mismatch - v2 instead of gqlparser.

Could get it working by adding alias in gqlgen/codegen/generated!.gotpl. However, am clueless how it fails only for me. Need help to find this out so that we can use it without the below patch.

Probable special scenarios are a) it is used in a bazel based project and b) code generated using gqlgen/api package instead of go run.

Patch:

diff --git a/codegen/generated!.gotpl b/codegen/generated!.gotpl
index 03be286e..76768c72 100644
--- a/codegen/generated!.gotpl
+++ b/codegen/generated!.gotpl
@@ -8,7 +8,7 @@
 {{ reserveImport "errors"  }}
 {{ reserveImport "bytes"  }}

-{{ reserveImport "github.com/vektah/gqlparser/v2" }}
+{{ reserveImport "github.com/vektah/gqlparser/v2" "gqlparser" }}
 {{ reserveImport "github.com/vektah/gqlparser/v2/ast" }}
 {{ reserveImport "github.com/99designs/gqlgen/graphql" }}
 {{ reserveImport "github.com/99designs/gqlgen/graphql/introspection" }}

sateeshpnv added a commit to sateeshpnv/gqlgen that referenced this issue Jul 23, 2020
mtibben added a commit that referenced this issue Jul 23, 2020
[issue #1258] explicitly add gqlparser alias to vektah/gqlparser/v2 import
@sateeshpnv
Copy link
Contributor Author

Closing the issue now that the PR was merged. However, still don't know how only I faced the original issue.

cgxxv pushed a commit to cgxxv/gqlgen that referenced this issue Mar 25, 2022
cgxxv pushed a commit to cgxxv/gqlgen that referenced this issue Mar 25, 2022
[issue 99designs#1258] explicitly add gqlparser alias to vektah/gqlparser/v2 import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant