tonyghita / graphql-go-example

Example use of github.com/graph-gophers/graphql-go
265 stars 77 forks source link

can't get it to build #1

Closed jeberly closed 6 years ago

jeberly commented 6 years ago

Thanks again for this example, seems like a well structured example to help get people started.

I am having trouble getting it to build though, perhaps it is my inexperience with go generate or dep, but here is the errors I get even after I attempted to use go generate.

go build output

# github.com/me/graphql-go-example/vendor/github.com/tonyghita/graphql-go-example/schema
vendor/github.com/tonyghita/graphql-go-example/schema/schema.go:21: undefined: AssetNames
vendor/github.com/tonyghita/graphql-go-example/schema/schema.go:22: undefined: MustAsset
# github.com/me/graphql-go-example/vendor/github.com/nicksrandall/dataloader
vendor/github.com/nicksrandall/dataloader/inMemoryCache.go:51: not enough arguments in call to c.Get
    have (interface {})
    want ("context".Context, interface {})

Thanks for your help.

tonyghita commented 6 years ago

Thanks for the report! Looking into it today...

I still haven't figured out all the quirks with dep. I think this issue is due to a pruning issue where unused files are included in the vendor directory.

tonyghita commented 6 years ago

@jeberly I finally was able to get time to look into this. I've made some changes to the vendored files and Makefile. Does make server work for you to get the server listening on port 8000?

OscarYuen commented 6 years ago

@tonyghita I would like to ask how do you import graphql-go library by dep. When I run dep init on my own repository, it seems that graphql-go cannot detect it. And I manually add it in Gopkg.toml and run dep ensure. It still has nothing changed. But other library works well in dep except graphql-go and go-jwt one. Thanks~

tonyghita commented 6 years ago

@OscarYuen make sure you run both dep init and dep ensure.

I'm not sure if dep checks your code for usages, but in my experience some dependency managers won't import libraries that are unused. Ensure that you've got a usage of github.com/neelance/graphql-go in your repository and I'd expect that to work.

Once you've got a usage in your code, you can dep prune to remove unused files from your vendor directory.

jeberly commented 6 years ago

@tonyghita make server work for me now. Huge thanks for fixing!

aquiseb commented 6 years ago

Hi, I'm getting this issue too, am I missing something or is it a bug? Thx

$ make server
▶ Fetching github.com/golang/dep...
go get github.com/golang/dep/cmd/dep
▶ Ensuring vendored dependencies are up-to-date...
dep ensure && dep prune
▶ Embedding schema files into binary...
go generate ./schema
▶ Starting development server...
go run server.go
# graphql-go-example/vendor/github.com/tonyghita/graphql-go-example/schema
vendor/github.com/tonyghita/graphql-go-example/schema/schema.go:21:23: undefined: AssetNames
vendor/github.com/tonyghita/graphql-go-example/schema/schema.go:22:8: undefined: MustAsset
Makefile:18: recipe for target 'server' failed
make: *** [server] Error 2
tonyghita commented 6 years ago

Hey, that looks like the go generate ./schema command didn't generate the expected code. What do you get if you only run the go generate ./schema command?

aquiseb commented 6 years ago

Hi @tonyghita, thanks for your reply. I have deleted bindata.go and run go generate ./schema, but getting exactly the same message. I can see that bindata.go was re-generated though.

aquiseb commented 6 years ago

@tonyghita I think the issue comes from the fact that it is trying to find AssetName and MustAsset from vendor/github.com/tonyghita/graphql-go-example/schema/schema.go.

But in vendor/github.com/tonyghita/graphql-go-example/schema/schema.go, the bindata.go was not generated!

So I copied my local MYGOPATH/src/graphql-go-example/schema/bindata.go to MYGOPATH/src/graphql-go-example/vendor/github.com/tonyghita/graphql-go-example/schema/ and ran server.go and it worked.

I guess bindata.go was added to .gitignore later on, so the problem only occurs to newcomers...?

What would you advise to avoid this?

Thanks

tonyghita commented 6 years ago

Ahh, so this project isn't meant to be vendored itself. It's an example application that you'd run on a server.