gqlgen icon indicating copy to clipboard operation
gqlgen copied to clipboard

Plugin code gen fails in vendor mode

Open adrianlungu opened this issue 1 year ago • 2 comments

What happened?

When using -mod=vendor, the project should properly account for imports; however, one of the imports is not added to the mod file due to it being specified only in the go template file resulting in:

merging type systems failed: unable to build object definition: unable to find type: github.com/99designs/gqlgen/graphql/introspection.Schema

The offending file is github.com/99designs/gqlgen/codegen/root_.gotpl where {{ reserveImport "github.com/99designs/gqlgen/graphql/introspection" }} is reserved but not imported explicitly anywhere.

Using _ "github.com/99designs/gqlgen/graphql/introspection" fixes the issue but this should probably be included in the project and not in projects importing the package.

Keep in mind this is in a plugin project that imports gqlgen.

What did you expect?

Code generation to work successfully after running go mod vendor and go mod tidy in vendor mode via -mod=vendor set in GOFLAGS.

Minimal graphql.schema and models to reproduce

N/A

versions

  • go run github.com/99designs/gqlgen version?

github.com/99designs/gqlgen v0.17.34

  • go version?

go version go1.20.5 darwin/arm64

adrianlungu avatar Jul 11 '23 08:07 adrianlungu

I just ran into this too, thanks for documenting it. Was there an actual work around found? You said you imported the subpackage but I'm not sure exactly where you imported it to.

bradhe avatar Dec 18 '23 22:12 bradhe

@bradhe yes, I have a cmd/generate/main.go file in which I have the code that loads the gqlgen codegen config, and calls api.Generate; in there, I added the following import

_ "github.com/99designs/gqlgen/graphql/introspection"

to make sure that the code will run.

adrianlungu avatar Dec 18 '23 22:12 adrianlungu