gqlgen: go generate gives missing go sum entry for module errors

What happened?

running go generate ./... gives go package errors

../../../../../go/pkg/mod/github.com/99designs/gqlgen@v0.13.0/cmd/gen.go:9:2: missing go.sum entry for module providing package github.com/urfave/cli/v2
../../../../../go/pkg/mod/github.com/99designs/gqlgen@v0.13.0/internal/imports/prune.go:15:2: missing go.sum entry for module providing package golang.org/x/tools/go/ast/astutil
../../../../../go/pkg/mod/github.com/99designs/gqlgen@v0.13.0/internal/code/packages.go:8:2: missing go.sum entry for module providing package golang.org/x/tools/go/packages
../../../../../go/pkg/mod/github.com/99designs/gqlgen@v0.13.0/internal/imports/prune.go:16:2: missing go.sum entry for module providing package golang.org/x/tools/imports
graph/resolver.go:3: running "go": exit status 1

if i run go get on each of these dependencies the error goes away and i can generate files just fine, but they come back after 1-2 days. so its quite annoying to keep having to run these.

I’ve spoken to a couple of people who used gqlgen before and none of them had any problems so I’m sure its not a super big deal. But just looking to get some help to get rid of these errors.

What did you expect?

go generate to generate the files without these errors

Minimal graphql.schema and models to reproduce

this happens with even the default generated schema

versions

  • gqlgen version? v0.13.0
  • go version? go1.16beta1 darwin/arm64
  • dep or go modules? go modules

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 30
  • Comments: 24 (1 by maintainers)

Commits related to this issue

Most upvoted comments

Actually this from the introduction page fixed it for me, even though I did not have the time to find out what it’s actually doing:

printf '// +build tools\npackage tools\nimport _ "github.com/99designs/gqlgen"' | gofmt > tools.go
go mod tidy

I fixed with “go get -u github.com/99designs/gqlgen/cmd”

This works for me though I don’t know what it does

go run -mod=mod github.com/99designs/gqlgen generate

import _ “github.com/99designs/gqlgen/cmd” in your server.go or any other go files.

Deleting go.sum fixed it.

I figure that’s a general bug in Go 1.16: golang/go#44129 - I have troubles with other dependencies, too.

I use Go 1.17 and have the same issue.

Same with go 1.17

This works for me though I don’t know what it does

go run -mod=mod github.com/99designs/gqlgen generate

https://go.dev/ref/mod

The -mod=mod flag instructs the go command to attempt to find new modules providing missing packages and to update go.mod and go.sum. The go get and go mod tidy commands do this automatically.

And yeah, it helped me, too

Before every run of go generate ./... I need to run go get -d github.com/99designs/gqlgen to fix this issue. Adding //go:generate go get -d github.com/99designs/gqlgen before //go:generate go run github.com/99designs/gqlgen seems to work fine.

I figure that’s a general bug in Go 1.16: https://github.com/golang/go/issues/44129 - I have troubles with other dependencies, too.

In my gitlab ci i fixed build issue like this. Second line might not be relevant for you.

- go get github.com/99designs/gqlgen/cmd@v0.13.0 && go run github.com/99designs/gqlgen
- go run github.com/markbates/pkger/cmd/pkger

When you follow the tutorial, you end up with a folder graph and a file resolver.go inside it. In it, you add //go:generate go run github.com/99designs/gqlgen and to make it work, you add //go:generate go get github.com/99designs/gqlgen/cmd@v0.14.0 right before that. For reference, this is how my resolver.go looks like:

package graph

//go:generate go get github.com/99designs/gqlgen/cmd@v0.14.0
//go:generate go run github.com/99designs/gqlgen

type Resolver struct{}

Same issue here by the way, using gqlgen version 0.14.0, and Go version 1.17. No matter what, none of the solutions mentioned above work. Completely confused as to what the issue is!

Any help would be greatly appreciated!

Can we close this? @mtibben @peteole?

Something that works for me regarding the missing cmd package: in resolver.go, before the line //go:generate go run github.com/99designs/gqlgen, add //go:generate go get github.com/99designs/gqlgen/cmd@v0.14.0. It’s not pretty because from what I can see it installs this package only for it to get removed again, but - at least for me - it works so far.

@JonasDoe @peter9207 Thank you for tracking. This may be resolved by closed by https://github.com/golang/go/issues/44129#issuecomment-854975677.

upon further debugging it seems that when i manually run go get it adds them to my go.mod file. which is why the error disappears. but when i run go mod tidy it cleans up these dependencies cuz i dont use them anywhere. and i get the error again.