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

package github.com/99designs/gqlgen: no Go files in #800

Closed
coderste opened this issue Jul 22, 2019 · 12 comments
Closed

package github.com/99designs/gqlgen: no Go files in #800

coderste opened this issue Jul 22, 2019 · 12 comments

Comments

@coderste
Copy link
Contributor

coderste commented Jul 22, 2019

What happened?

When running go mod vendor and then adding //go:generate go run -mod=vendor github.com/99designs/gqlgen to the top of my resolver.go file when I try and run go generate -mod=vendor ./... I get the following error

package github.com/99designs/gqlgen: no Go files in /Users/shi03/code/projects/gs/common-api/vendor/github.com/99designs/gqlgen

What did you expect?

I expected the go generate -mod=vendor ./... to re-generate the gql generated files.

Minimal graphql.schema and models to reproduce

versions

  • gqlgen version? v0.9.1
  • go version? go version go1.12.6 darwin/amd64
  • dep or go modules? go modules

Unsure if this is an error on my end. But because I vendor all my dependancies when running any Go commands I add the -mod=vendor flag[1] to every command so that Go using the dependancies inside the vendor folder rather than the cache/downloading them.

[1] - https://github.com/golang/go/wiki/Modules#how-do-i-use-vendoring-with-modules-is-vendoring-going-away

@vektah
Copy link
Collaborator

vektah commented Jul 22, 2019

go run behaves a bit weird in vendor mode, I wrote gorunpkg to work around this behaviour. I haven't updated it to packages yet but if your still vendoring it might just work?

We ended up moving away from it in the getting started guide in favour of a local binary entry point.

https://gqlgen.com/getting-started-dep/

@coderste
Copy link
Contributor Author

I've tried install gorunpkg and adding //go:generate gorunpkg github.com/99designs/gqlgen to the top of my file.

Unfortunately I still get the same error:

pkg: go/build: importGo github.com/99designs/gqlgen: exit status 1
can't load package: package github.com/99designs/gqlgen: no Go files in /code/project/vendor/github.com/99designs/gqlgen

I've opened an issue on the Go repo golang/go#33240 to see what they recommend.

As this isn't an issue with the gqlgen package I'm happy for you to close this issue :)

@bugzpodder
Copy link

i've been using gohack, not sure if it would work for you

@coderste
Copy link
Contributor Author

coderste commented Jul 24, 2019

So just thought I'd come back and post the solution to this.

Based on information from golang/go#29516 what we can is the following:

Create a gqlgen file inside a scripts folder and add the following code

// +build tools

package main

import "github.com/99designs/gqlgen/cmd"

func main() {
	cmd.Execute()
}

See here how we use // +build tools instead of // +build ignore?

That's because build ignore will not work when trying to vendor dependancies. For example having build ignore will leave out the cmd folder of the 99designs/gqlgen package when using go mods.

What build tools will do though is pull in the dependancies into the vendor directory but will still ignore them dependancies when running go build as to not bloat your application.

Then inside the resolver.go file we can just have

//go:generate go run ../../scripts/gqlgen.go

This will then have go generate work with vendored modules

@akhiljain23
Copy link

As a workaround I did rm -rf vendor then ran go run github.com/99designs/gqlgen generate and then vendor again

@leandroruel
Copy link

jesus no matter what i do none of this solutions works for me, i'm already feeling dumb.

@khanakia
Copy link

@leandroruel just follow this tutorial https://gqlgen.com/getting-started/
This will work 100%

@leandroruel
Copy link

thanks @khanakia now i fixed it. \o/

@khanakia
Copy link

@leandroruel how exactly did you fix this ? Can you leave some information here so it will be helpful for other users in case they face the same issue in future.

@khanakia
Copy link

HERE's THE SOLUTION:

create a new file called gqlgen.go and place this code

// +build tools

package main

import (
	"fmt"

	"github.com/99designs/gqlgen/cmd"
)

func main() {
	fmt.Println("Building Graphql schema")
	cmd.Execute()
}

now run this commands

go mod vendor
go run ./gqlgen.go

OR you can used the command as generator by placing this code in your main.go

//go:generate go run ./gqlgen.go

after that you can simply run go generate command

@renxinhe
Copy link

I'm running into the same issue here. After trying the solution, I'm getting the following error:

$ go run ./gqlgen.go
gqlgen.go:9:2: no required module provides package github.com/99designs/gqlgen/cmd; to add it:
        go get github.com/99designs/gqlgen/cmd

$ go get github.com/99designs/gqlgen/cmd
go: module github.com/99designs/gqlgen@upgrade found (v0.17.22), but does not contain package github.com/99designs/gqlgen/cmd

My go.mod is showing gqlgen version v0.17.22. After looking at the current source code, I don't think the "cmd/" directory still exists. Does anyone know a to date solution to resolve this "no Go files" circular dependency issue between go mod tidy and go generate ./...?

@somatom98
Copy link

@renxinhe executing go get github.com/99designs/gqlgen@v0.17.40 did it for me

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

8 participants