Gqlgen: Custom model fails with error: unable to find type

Created on 9 Jul 2019  路  2Comments  路  Source: 99designs/gqlgen

What happened?

Trying to setup custom models in a project but gqlgen fails with:

$ go run github.com/99designs/gqlgen
merging failed: unable to build object definition: unable to find type github.com/jasonwilson/todos/todos.Todo

exit status 3

What did you expect?

gqlgen should be able to locate custom models specified in gqlgen.yml

Minimal graphql.schema and models to reproduce

schema.graphql

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!
}

todos.go

package todos

type Todo struct {
    ID     string
    Text   string
    Done   bool
    UserID string
}

gqlgen.yml

schema:
- schema.graphql
exec:
  filename: generated.go
model:
  filename: models_gen.go
resolver:
  filename: resolver.go
  type: Resolver
models:
  Todo:
    model: github.com/jasonwilson/todos/todos.Todo
autobind: []

versions

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

Most helpful comment

What did you do to fix this i followed the totorial exzactly and got the same issue.

I find it hard to beleave that go whould force you to make a github repo for evry project you make ?

All 2 comments

This turned out to be user error, nested models should be referenced from the parent module.

What did you do to fix this i followed the totorial exzactly and got the same issue.

I find it hard to beleave that go whould force you to make a github repo for evry project you make ?

Was this page helpful?
0 / 5 - 0 ratings