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

Resolver field was not generated? #658

Closed
ShawnRong opened this issue Apr 2, 2019 · 4 comments
Closed

Resolver field was not generated? #658

ShawnRong opened this issue Apr 2, 2019 · 4 comments
Labels
support please use https://discord.gg/DYEq3EMs4U for support questions

Comments

@ShawnRong
Copy link

What happened?

I'm using gqlgen to generate resolver automatically.But when I apply relationships in my models, the related model field resolve was not generate correctly.
Here's my defined models:
models/Article.go

type Article struct {
	Model
	Title    string    `json: "title"`
	Content  string    `json: "content"`
	UserID   uint      `json: "user_id"`
	User     User      `json: "user"`
	Comments []Comment `json: "comments"`
	Tags     []*Tag    `json:"tags" gorm:"many2many:article_tags"`
}

models/User.go

type User struct {
	Model
	Email    string    `gorm:"type:varchar(100);unique_index" json:"email" binding:"required,email"`
	Name     string    `json:"name"`
	Role     string    `gorm:"size:255" json:"role"`
	Active   bool      `gorm:"default: false" json:"active"`
	Password string    `json:"password"`
	Articles []Article `json: "articles"`
	Comments []Comment `json: "comments"`
}

models/Comment.go

type Comment struct {
	Model
	Content   string  `json: "content"`
	UserID    uint    `json: "user_id"`
	User      User    `json: "user"`
	ArticleID uint    `json: "article_id"`
	Article   Article `json: "article"`
}

models/Tag.go

type Tag struct {
	Model
	Name     string     `json: "name"`
	Articles []*Article `json: "articles" gorm:"many2many:article_tags"`
}

What did you expect?

I suppose the tagResolver commentResolver will auto generated in my resolver.go file, right? But I only get mutationResolver and queryResolver

Minimal graphql.schema and models to reproduce

type User {
    id: ID!
    email: String!
    name: String!
    role: String!
    active: String!
    password: String!
    created_at: Time!
    updated_at: Time!
    deleted_at: Time!
    articles: [Article!]
    comments: [Comment!]
}

type Tag {
    id: ID!
    name: String!
    created_at: Time!
    updated_at: Time!
    deleted_at: Time!
    articles: [Article!]!
}

type Article {
    id: ID!
    title: String!
    content: String!
    user: User!
    created_at: Time!
    updated_at: Time!
    deleted_at: Time!
    tags: [Tag!]!
    comments: [Comment!]
}

type Comment {
   id: ID!
   content: String!
   user: User!
   created_at: Time!
   updated_at: Time!
   deleted_at: Time!
   article: Article!
}

type Query {
    Users(limit: Int = 25, offset: Int = 0): [User!]!
    Me(id: Int!): User!
    Article(id: ID = 0, tag: String = ""): Article!
    Articles(limit: Int = 25, offset: Int = 0): [Article!]!
    Tags: [Tag!]!
}

versions

  • gqlgen version: 0.8.2
  • go version: 1.11.4
  • go modules

Anyone can help me out? Thanks

@ShawnRong
Copy link
Author

Solved. Just add field resolver config in the gqlgen.yml

@vektah vektah added the support please use https://discord.gg/DYEq3EMs4U for support questions label May 15, 2019
@victorkt
Copy link

victorkt commented Nov 7, 2019

For anyone coming to this issue from google, this is what you should do to have the other resolvers generated: #350 (comment)

@frederikhors
Copy link
Collaborator

@ShawnRong I see you're using uint for IDs. Can I ask you how to use uint in my project too? What are you setting in your gqlgen.yml for them to work?

Thanks.

@ShawnRong
Copy link
Author

ShawnRong commented Oct 21, 2020

@frederikhors , Here's the link of gqlgen.yml file https://github.com/ShawnRong/bento/blob/master/gqlgen.yml. Actually I don't remember this issue 😂 , Hope this link can help you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support please use https://discord.gg/DYEq3EMs4U for support questions
Projects
None yet
Development

No branches or pull requests

4 participants