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

Getting started doc is broken to run init cmd #609

Closed
fzxu opened this issue Mar 11, 2019 · 18 comments
Closed

Getting started doc is broken to run init cmd #609

fzxu opened this issue Mar 11, 2019 · 18 comments
Assignees
Labels
bug Something isn't working v0.8.2 Fixed in 0.8.2

Comments

@fzxu
Copy link

fzxu commented Mar 11, 2019

Expected Behaviour

should continue generate what ever it should.

Actual Behavior

merging failed: unable to build object definition: unable to find type github.com/99designs/gqlgen/graphql/introspection.InputValue

Minimal graphql.schema and models to reproduce

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!
}
@mathewbyrne
Copy link
Contributor

Are you using the latest version 0.8.1, and are you using Go Modules or dep to initialise?

@fzxu
Copy link
Author

fzxu commented Mar 11, 2019

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.

@mathewbyrne mathewbyrne added the bug Something isn't working label Mar 12, 2019
@mathewbyrne
Copy link
Contributor

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.

@vektah vektah added the v0.8.2 Fixed in 0.8.2 label Mar 13, 2019
@mathewbyrne
Copy link
Contributor

Fixed in #628

@flavianmissi
Copy link

flavianmissi commented Mar 19, 2019

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. :/

@fzxu
Copy link
Author

fzxu commented Mar 19, 2019

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

@mathewbyrne
Copy link
Contributor

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.

@fzxu
Copy link
Author

fzxu commented Mar 19, 2019

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.

@mathewbyrne
Copy link
Contributor

Ok I can see a couple of problems in the dep docs:

  1. 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

  2. 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

@fzxu
Copy link
Author

fzxu commented Mar 19, 2019

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.

@mec07
Copy link

mec07 commented May 21, 2019

Clearing out all the generated files, then executing:

go mod init

and then rerunning gqlgen resolved these types of issues for me.

@Szymongib
Copy link

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.

@kisinga
Copy link

kisinga commented Jul 8, 2019

For anyone still struggling with this,
take a look at this answer
Make sure to run go mod tidy after conversion

@caldempsey
Copy link

Starting to see this issue again

@timohuovinen
Copy link

Looks like the issue is caused by go not downloading the introspection directory, at least I don't see it in my vendor, copying it over manually from this repo fixed the issue for me.

@mwillfox
Copy link

mwillfox commented May 26, 2022

For anyone running into this issue on v0.17.8, @timohuovinen has the correct fix. You can force mod to grab the introspection directory by updating your tools.go:

//go:build tools
// +build tools

package tools

import (
	_ "github.com/99designs/gqlgen"
	_ "github.com/99designs/gqlgen/graphql/introspection"
)

@PrashantRaj18198
Copy link

This does not work when you are using a 'vendor' folder. Check your vendor folder the 'introspection.Directive' file is missing there. As a work around, remove the vendor folder, delete all the generated files and rerun the .../gqlgen init command.

@mufaddaltahir
Copy link

For anyone running into this issue on v0.17.8, @timohuovinen has the correct fix. You can force mod to grab the introspection directory by updating your tools.go:

//go:build tools
// +build tools

package tools

import (
	_ "github.com/99designs/gqlgen"
	_ "github.com/99designs/gqlgen/graphql/introspection"
)

did not fix the issue for me
gqlgen version v0.17.16
golang version 1.21.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v0.8.2 Fixed in 0.8.2
Projects
None yet
Development

No branches or pull requests