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

Issues Generating Client After go mod tidy #160

Closed
jenslauterbach opened this issue Dec 10, 2021 · 3 comments
Closed

Issues Generating Client After go mod tidy #160

jenslauterbach opened this issue Dec 10, 2021 · 3 comments
Labels
documentation Improvements or additions to documentation

Comments

@jenslauterbach
Copy link

jenslauterbach commented Dec 10, 2021

Disclaimer: I am not sure how to fix this or if this is a issue with go mod.

Describe the bug

  • Installed the genqlient: go get github.com/Khan/genqlient
  • go.mod contains several indirect dependencies required by go generate . (see below)
  • I can run go generate . successfully
  • Then I run go mod tidy, which removes all the required indirect dependencies of genqlient (see below).
  • Now I can't run go generate . anymore, because dependencies are missing (see error below)

Error:

../../go/pkg/mod/github.com/vektah/gqlparser/[email protected]/validator/suggestionList.go:7:2: missing go.sum entry for module providing package github.com/agnivade/levenshtein (imported by github.com/vektah/gqlparser/v2/validator); to add:
        go get github.com/vektah/gqlparser/v2/[email protected]
../../go/pkg/mod/github.com/!khan/[email protected]/generate/main.go:13:2: missing go.sum entry for module providing package github.com/alexflint/go-arg (imported by github.com/Khan/genqlient/generate); to add:
        go get github.com/Khan/genqlient/[email protected]
../../go/pkg/mod/github.com/!khan/[email protected]/generate/generate.go:19:2: missing go.sum entry for module providing package golang.org/x/tools/imports (imported by github.com/Khan/genqlient/generate); to add:
        go get github.com/Khan/genqlient/[email protected]
../../go/pkg/mod/github.com/!khan/[email protected]/generate/config.go:10:2: missing go.sum entry for module providing package gopkg.in/yaml.v2 (imported by github.com/Khan/genqlient/generate); to add:
        go get github.com/Khan/genqlient/[email protected]
main.go:25: running "go": exit status 1

To Reproduce

  1. Download attached zip: go-mod-tidy-issue.zip
  2. Extract archive
  3. Run go generate .
  4. A new file generated.go should be created (you can also run go run . to verify that the generated client works)
  5. Run go mod tidy
  6. Check go.mod, most indirect dependencies have been removed
  7. Run go generate . again
  8. Error should appear

Expected behavior

When running go mod tidy required dependencies are not removed.

genqlient version

v0.3.0

Additional context

go.mod after go get github.com/Khan/genqlient:

module genqclientbug

go 1.17

require github.com/Khan/genqlient v0.3.0

require (
	github.com/agnivade/levenshtein v1.0.3 // indirect
	github.com/alexflint/go-arg v1.4.2 // indirect
	github.com/alexflint/go-scalar v1.0.0 // indirect
	github.com/vektah/gqlparser/v2 v2.1.0 // indirect
	golang.org/x/mod v0.4.2 // indirect
	golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect
	golang.org/x/tools v0.1.5 // indirect
	golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
	gopkg.in/yaml.v2 v2.4.0 // indirect
)

go.mod after running go mod tidy:

module genqclientbug

go 1.17

require github.com/Khan/genqlient v0.3.0

require github.com/vektah/gqlparser/v2 v2.1.0 // indirect

go-mod-tidy-issue.zip

@jenslauterbach jenslauterbach added the bug Something isn't working label Dec 10, 2021
@jenslauterbach jenslauterbach changed the title Issues Generating Client after go mod tidy Issues Generating Client After go mod tidy Dec 10, 2021
@benjaminjkraft
Copy link
Collaborator

benjaminjkraft commented Dec 10, 2021

Thanks for the report! This looks to be golang/go#45552; see in particular this comment. In short, if you want to be able to go run on newer Go you'll need to have a (blank) import of genqlient's entrypoint in a special tools.go file somewhere in your module so go mod tidy doesn't prune it. (This only matters on newer Go which is more aggressive about its pruning, such that the import of github.com/Khan/genqlient/graphql no longer suffices as it doesn't import all the third-party deps.)

This is ultimately a Go modules problem so we can't fix it, but I'll leave this issue since we should probably mention it in genqlient docs. We'll need to figure out the best thing to recommend.

@benjaminjkraft benjaminjkraft added documentation Improvements or additions to documentation and removed bug Something isn't working labels Dec 10, 2021
@jenslauterbach
Copy link
Author

@benjaminjkraft Thank you for the help. Very much appreciated. I will check if the provided workaround int he comment works 👍

@jenslauterbach
Copy link
Author

Just came back here and can report that the workaround did in fact worked.

I use a tools.go with the following code:

//go:build tools
// +build tools

package client

import (
	_ "github.com/Khan/genqlient"
)

This fixed the issue.

benjaminjkraft added a commit that referenced this issue Apr 29, 2022
This came up in #160, and will surely come up again. I hope the Go
folks figure out something better here, but until such time...
benjaminjkraft added a commit that referenced this issue Apr 29, 2022
This came up in #160, and will surely come up again. I hope the Go
folks figure out something better here, but until such time...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants