Closed KellyLSB closed 2 years ago
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:
go mod init
in your project root, which will create a go.mod
file go run github.com/99designs/gqlgen init
which should now work without that errorrequire
list in the project go.mod
fileIf 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)
If @diffuse's answer solves it please close this issue, @KellyLSB.
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
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
)
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:
github.com/vektah/gqlparser/v2 v2.2.0
to github.com/vektah/gqlparser/v2 v2.1.0
graph/prelude.resolvers.go
go run github.com/99designs/gqlgen init
Credit to FreezeLook for this solution.
Looks like this change is being discussed over in https://github.com/vektah/gqlparser/issues/154.
@diffuse The solution worked for me. Thank you.
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.
@KellyLSB please tell me if this is still an issue with v0.16.0 and I'll re-open it.
What happened?
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
? mastergo version
? go1.15.5 linux/amd64This has not been a problem in my older application of gqlgen; merely the new init.