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

gqlgen init error in loading gqlparser. #1402

Closed
KellyLSB opened this issue Nov 30, 2020 · 9 comments
Closed

gqlgen init error in loading gqlparser. #1402

KellyLSB opened this issue Nov 30, 2020 · 9 comments

Comments

@KellyLSB
Copy link

What happened?

kellylsbkr@penguin:~/go/src/github.com/KellyLSB/angelrin$ go run github.com/99designs/gqlgen init
validation failed: packages.Load: graph/generated/generated.go:16:2: cannot find package "github.com/vektah/gqlparser/v2" in any of:
        /usr/local/go/src/github.com/vektah/gqlparser/v2 (from $GOROOT)
        /home/kellylsbkr/go/src/github.com/vektah/gqlparser/v2 (from $GOPATH)
graph/generated/generated.go:17:2: cannot find package "github.com/vektah/gqlparser/v2/ast" in any of:
        /usr/local/go/src/github.com/vektah/gqlparser/v2/ast (from $GOROOT)
        /home/kellylsbkr/go/src/github.com/vektah/gqlparser/v2/ast (from $GOPATH)
/home/kellylsbkr/go/src/github.com/KellyLSB/angelrin/graph/generated/generated.go:16:12: could not import github.com/vektah/gqlparser/v2 (invalid package name: "")
/home/kellylsbkr/go/src/github.com/KellyLSB/angelrin/graph/generated/generated.go:17:2: could not import github.com/vektah/gqlparser/v2/ast (invalid package name: "")

Exec "go run ./server.go" to start GraphQL server

What did you expect?

A v2 directory within gqlparser; or... something

Minimal graphql.schema and models to reproduce

This is the project init

versions

  • gqlgen version? master
  • go version? go1.15.5 linux/amd64
  • dep or go modules? neither, yet

This has not been a problem in my older application of gqlgen; merely the new init.

@diffuse
Copy link

diffuse commented Dec 19, 2020

This is referenced in #1105, if you look at the go.mod file for gqlgen, you can see that the module is defined as github.com/vektah/gqlparser/v2.

Like #1105 says, if you're not running in go module mode, I believe $GOPATH/src is searched for github.com/vektah/gqlparser/v2, which won't exist, since go get downloads it to github.com/vektah/gqlparser

If you're ok with using go module mode, then an easy fix for it is to:

  • run go mod init in your project root, which will create a go.mod file
  • re-run go run github.com/99designs/gqlgen init which should now work without that error
  • this command should also add the appropriate modules to the require list in the project go.mod file

If your project is called foo, your go.mod file will end up looking something like this:

module github.com/<your username>/foo

go 1.15

require (
	github.com/99designs/gqlgen v0.13.0
	github.com/vektah/gqlparser/v2 v2.1.0
)

When you run go install ./..., your other dependencies should also be automatically added to this file.

Your previous application probably used a sub-2.0 version of gqlgen, which would have the module defined without the v2 (go.mod)

@frederikhors
Copy link
Collaborator

If @diffuse's answer solves it please close this issue, @KellyLSB.

@KellyLSB
Copy link
Author

KellyLSB commented Dec 29, 2020

Presently:

kellylsbkr@penguin:~/go/src/github.com/KellyLSB/demondin$ go run github.com/99designs/gqlgen init
package github.com/99designs/gqlgen: no Go files in /home/kellylsbkr/go/src/github.com/KellyLSB/demondin/vendor/github.com/99designs/gqlgen
kellylsbkr@penguin:~/go/src/github.com/KellyLSB/demondin$ ls vendor/github.com/99designs/gqlgen/
complexity  graphql  handler  LICENSE

I've run go mod init && go mod vendor

go.mod

module github.com/KellyLSB/demondin

go 1.15

require (
	github.com/99designs/gqlgen v0.13.0
	github.com/agnivade/levenshtein v1.1.0 // indirect
	github.com/araddon/dateparse v0.0.0-20201001162425-8aadafed4dc4
	github.com/go-macaron/inject v0.0.0-20200308113650-138e5925c53b // indirect
	github.com/go-macaron/session v1.0.1
	github.com/gobuffalo/flect v0.2.2
	github.com/google/uuid v1.1.2
	github.com/gorilla/websocket v1.4.2
	github.com/hashicorp/golang-lru v0.5.4 // indirect
	github.com/jinzhu/gorm v1.9.16
	github.com/joho/godotenv v1.3.0
	github.com/kr/pretty v0.2.1
	github.com/kr/text v0.2.0 // indirect
	github.com/lib/pq v1.8.0
	github.com/stripe/stripe-go v56.1.0+incompatible
	github.com/vektah/gqlparser v1.3.1
	golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9 // indirect
	golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect
	gopkg.in/ini.v1 v1.62.0 // indirect
	gopkg.in/macaron.v1 v1.4.0
	gopkg.in/yaml.v2 v2.3.0
)

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

@rokiyama
Copy link

I have had the same issue, I have run go get github.com/vektah/gqlparser/v2 but I still get the another error.

$ go run github.com/99designs/gqlgen init
validation failed: packages.Load: /Users/rokiyama/projects/gqlgen-todos/graph/prelude.resolvers.go:19:44: __DirectiveResolver not exported by package generated

full logs:

$ mkdir gqlgen-todos
$ cd gqlgen-todos
$ go mod init github.com/rokiyama/gqlgen-todos
go: creating new go.mod: module github.com/rokiyama/gqlgen-todos

$ go get github.com/99designs/gqlgen
go get: added github.com/99designs/gqlgen v0.13.0

$ go get github.com/vektah/gqlparser/v2
go get: upgraded github.com/vektah/gqlparser/v2 v2.1.0 => v2.2.0

$ go run github.com/99designs/gqlgen init
validation failed: packages.Load: /Users/rokiyama/projects/gqlgen-todos/graph/prelude.resolvers.go:19:44: __DirectiveResolver not exported by package generated

Exec "go run ./server.go" to start GraphQL server

$ go run ./server.go
# github.com/rokiyama/gqlgen-todos/graph
graph/prelude.resolvers.go:19:34: cannot refer to unexported name generated.__DirectiveResolver

my go.mod:

module github.com/rokiyama/gqlgen-todos

go 1.16

require (
        github.com/99designs/gqlgen v0.13.0 // indirect
        github.com/vektah/gqlparser/v2 v2.2.0 // indirect
)

@diffuse
Copy link

diffuse commented Apr 21, 2021

Looks like this may be an issue with gqlparser v2.2.0 (released 8 days ago as of this post). I haven't looked into the specifics, but I just was able to replicate the behavior you mention on my system, then fix it with the resolution mentioned here.

Basically, in your go.mod file:

  • rollback the version of gqlparser from github.com/vektah/gqlparser/v2 v2.2.0 to github.com/vektah/gqlparser/v2 v2.1.0
  • delete graph/prelude.resolvers.go
  • rerun go run github.com/99designs/gqlgen init

Credit to FreezeLook for this solution.

@diffuse
Copy link

diffuse commented Apr 21, 2021

Looks like this change is being discussed over in vektah/gqlparser#154.

@rokiyama
Copy link

@diffuse The solution worked for me. Thank you.

@wangzuo
Copy link

wangzuo commented May 22, 2021

I guess https://github.com/99designs/gqlgen/blob/master/graphql/introspection/introspection.go#L12 is missing in v0.13.0, so a new release will fix this issue #1534.
go get github.com/99designs/gqlgen@master will also work for now.

bensooraj added a commit to bensooraj/rndmicu that referenced this issue Jul 4, 2021
@frederikhors
Copy link
Collaborator

@KellyLSB please tell me if this is still an issue with v0.16.0 and I'll re-open it.

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

5 participants