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

Question on ent to gqlgen model binding #3

Open
florian-nguyen opened this issue Jul 16, 2022 · 5 comments
Open

Question on ent to gqlgen model binding #3

florian-nguyen opened this issue Jul 16, 2022 · 5 comments

Comments

@florian-nguyen
Copy link

While following your great tutorial on gqlgen/ent clean architecture on Medium, I am having difficulty binding my TodoStatus from ent using the gqlgen.yaml file using the following lines.

  TodoStatus:
    model:
      - go-ent-gqlgen/ent/todo.Status

Despite spending quite some time trying to understand what I am missing here, I am still having the following error upon running the gqlgen command, and I wanted to ask if it is familiar to you:

validation failed: packages.Load: -: package go-ent-gqlgen/graph/model is not in GOROOT (/usr/local/go/src/go-ent-gqlgen/graph/model)

At this point I am suspecting a wrong configuration of Go on my machine, but as someone relatively new to the language I was unable to find what is causing my issue. I would really appreciate if you could help me find the root cause.

go env output
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/floriannguyen/Library/Caches/go-build"
GOENV="/Users/floriannguyen/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/floriannguyen/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/floriannguyen/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/floriannguyen/go/src/github.com/florian-nguyen/go-ent-gqlgen/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/6b/kd8wb_kx69ld3qr8h70qb0y80000gn/T/go-build2828287172=/tmp/go-build -gno-record-gcc-switches -fno-common"

And allow me at last to thank you for your articles. It is quite difficult to find advanced tutorials on Golang and I enjoy very much learning through yours.

Thank you,
Florian

@manakuro
Copy link
Owner

@florian-nguyen
Thank you for your question.

It seems like gqlgen couldn't find the model file. Could you check the autobind in your gqlgen.yml? It should look something like this:

autobind:
  - go-ent-gqlgen/pkg/entity/model
  - go-ent-gqlgen/ent

And make sure that module name is correct in your go.mod file:

module go-ent-gqlgen

If you can't figure it out, let me see your code so that I can find out what happens.

@florian-nguyen
Copy link
Author

florian-nguyen commented Jul 24, 2022

Hello @manakuro,

Thanks for your kind reply. My autobind was correct, but turns out I hadn't commented the "model" section in gqlgen.yml. After that, other errors kept coming, and although I checked my schema files, gqlgen.yml and schema definition in ent:

  • For some reason, in my case TodoStatus type becomes TodoTodoStatus in ent.graphqls
  • I'm still getting an error when running gqlgen, only when trying to bind my TodoStatustype (otherwise working perfectly fine) :
    validation failed: packages.Load: -: package go-ent-gqlgen is not in GOROOT (/usr/local/go/src/go-ent-gqlgen)

I spent quite some time trying to solve these issues, to no avail. Eventually I just manually corrected the mistakes in the generated files. Apart from this I was able to complete the tutorial, and I learned a lot so I am grateful to you for the time you spent on it.

On a completely different topic, how are you able to have a dark theme in the playground ? Looks like the Apollo playground, but I am seeing GraphiQL's playground instead.

I don't mind sharing my code. I'd be grateful if you could tell me what's happening there, but if it takes you too much time then nevermind, I'll probably figure it out one day... Here's my code : https://github.com/florian-nguyen/go-ent-gqlgen

Thanks to you,
Florian

@manakuro
Copy link
Owner

Thanks for the clarification. @florian-nguyen

For some reason, in my case TodoStatus type becomes TodoTodoStatus in ent.graphqls

entgo.io/contrib has something to do with that. I could reproduce the issue by using entgo.io/contrib@v0.3.0.

Could you get the following version and try it out again?

Install entgo.io/ent@v0.10.1:

go get entgo.io/ent@v0.10.1

And the go.mod should look like this:

	entgo.io/contrib v0.2.0
	entgo.io/ent v0.10.1

On a completely different topic, how are you able to have a dark theme in the playground ? Looks like the Apollo playground, but I am seeing GraphiQL's playground instead.

Because gqlgen has replaced the playground with GraphiQL at some point. I was using the v0.14.0, so it's still the GraphQL Playground.

99designs/gqlgen#1751

@florian-nguyen
Copy link
Author

Hello @manakuro,

Thanks a lot for these tips! Working better now with the ent versions you indicated.

With these changes, the binding to ent/todo.Statusseems to be successful and I am able to run my server and query successfully. Still seeing this error when running gqlgen though (v0.17.13), although it does not seem to prevent my code from running eventually. No manual update required anymore, so I can live with this error, although I'd prefer to understand what I'm missing here.

validation failed: packages.Load: -: package go-ent-gqlgen is not in GOROOT (/usr/local/go/src/go-ent-gqlgen)

exit status 1
make: *** [gqlgen] Error 1

Where you able to reproduce this error last time you had a look at this issue?

@manakuro
Copy link
Owner

Okay, I confirmed that error with gqlgen@v0.17.13. I will check it out.

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

2 participants