should continue generate what ever it should.
merging failed: unable to build object definition: unable to find type github.com/99designs/gqlgen/graphql/introspection.InputValue
type Todo {
id: ID!
text: String!
done: Boolean!
user: User!
}
type User {
id: ID!
name: String!
}
type Query {
todos: [Todo!]!
}
input NewTodo {
text: String!
userId: String!
}
type Mutation {
createTodo(input: NewTodo!): Todo!
}
Are you using the latest version 0.8.1, and are you using Go Modules or dep to initialise?
I am following the dep way: https://gqlgen.com/getting-started-dep/
I did not specify which gqlgen version. I believe it is from master.
Ok, yeah dep isn't getting the ambient imports it needs from https://github.com/99designs/gqlgen/blob/master/ambient.go.
As a workaround for now, if you include these imports in your scripts/gqlgen.go file from the getting started docs, you should be able to get the init command running.
Fixed in #628
Same problem here with dep, gqlgen v0.8.2.
Tried adding the imports listed in ambient.go to my scripts/gqlgen.go but that didn't fix it for me either. :/
I got the new error merging failed: unable to build object definition: unable to find type github.xxx.com/fxu/gqlgen_todos.Todo
I have the todo.go file under gqlgen_todos package. What could be wrong? @mathewbyrne
I'm unable to reproduce in 0.8.2:
$ mkdir tmp
$ cd tmp
$ ls
$ mkdir scripts
$ vim scripts/gqlgen.go
$ dep init
Locking in v0.5.1 (7087cb7) for transitive dep github.com/hashicorp/golang-lru
Locking in v1.20.0 (cfb3883) for transitive dep github.com/urfave/cli
Locking in v1.1.2 (05741cd) for transitive dep github.com/vektah/gqlparser
Locking in master (bb1270c) for transitive dep golang.org/x/tools
Locking in v0.8.1 (ba968bf) for transitive dep github.com/pkg/errors
Using ^0.8.2 as constraint for direct dep github.com/99designs/gqlgen
Locking in v0.8.2 (ee06517) for direct dep github.com/99designs/gqlgen
Locking in v1.4.0 (66b9c49) for transitive dep github.com/gorilla/websocket
Locking in v2.2.2 (51d6538) for transitive dep gopkg.in/yaml.v2
Locking in v1.0.1 (834b435) for transitive dep github.com/agnivade/levenshtein
$ vim schema.graphql
$ go run scripts/gqlgen.go init
Exec "go run ./server/server.go" to start GraphQL server
$ dep ensure
$ go run ./server/server.go
2019/03/20 08:22:09 connect to http://localhost:8080/ for GraphQL playground
If you're still having issues can you give the exact steps to reproduce.
Also worth noting that this dep method wont supported much further once Go Modules gets wider adoption. If it's possible for you I would definitely recommend using Go 1.12+ and Go Modules.
that part works for me. but if you go a little further in that doc: https://gqlgen.com/getting-started-dep/#create-the-database-models
what I don't know is the .Todo file. It was not asked to create nor it's not a go file.
Ok I can see a couple of problems in the dep docs:
You need to ensure that the todo.go file has the correct package name for it's location. So for example, if my project was in github.com/99designs/todos then the package name should also be todos
Check that your mapping in gqlgen.yml is also correctly pointing to the right model. So for the example above:
models:
Todos:
model: github.com/99designs/todos.Todo
I think I followed that correctly. The package name is gqlgen_todos and the model path is github.xxx.com/fxu/gqlgen_todos.Todo
If I change to a wrong path it will say can not find file. but it show can not find type which seems both the path and package are correct.
Clearing out all the generated files, then executing:
go mod init
and then rerunning gqlgen resolved these types of issues for me.
If anyone using dep still having that issue I suggest trying to add
[[prune.project]]
name = "github.com/99designs/gqlgen"
non-go = false
to the Gopkg.toml file, as apparently, the library is using some Go templates files for code generation.
I use version 0.9.0.
For anyone still struggling with this,
take a look at this answer
Make sure to run go mod tidy after conversion
Starting to see this issue again
Most helpful comment
Clearing out all the generated files, then executing:
and then rerunning gqlgen resolved these types of issues for me.