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

Fix getting-started docs missing fields resolver config & Todo struct UserID field #2157

Merged
merged 1 commit into from
May 16, 2022

Conversation

a70537952
Copy link
Contributor

  1. Fix missing fields resolver config before execute go run github.com/99designs/gqlgen generate on Getting Started causing not generating user resolver

  2. Add UserID to Todo struct to fix missing obj.UserID on User resolver

func (r *todoResolver) User(ctx context.Context, obj *model.Todo) (*model.User, error) {
	return &model.User{ID: obj.UserID, Name: "user " + obj.UserID}, nil // Missing obj.UserID
}

I have:

  • Added tests covering the bug / feature (see testing)
  • Updated any relevant documentation (see docs)

Relevent Issue #2146 #2144

Fix getting-started missing fields resolver config
@@ -211,6 +236,7 @@ type Todo struct {
ID string `json:"id"`
Text string `json:"text"`
Done bool `json:"done"`
UserID string `json:"userId"`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello @a70537952 , I also had this problem but it has been fixed with your guidance here.
may I know why you adding new UserID in this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Snippet from Getting Started doc

func (r *mutationResolver) CreateTodo(ctx context.Context, input model.NewTodo) (*model.Todo, error) {
	todo := &model.Todo{
		Text:   input.Text,
		ID:     fmt.Sprintf("T%d", rand.Int()),
		User:   &model.User{ID: input.UserID, Name: "user " + input.UserID},
	}
	r.todos = append(r.todos, todo)
	return todo, nil
}

func (r *todoResolver) User(ctx context.Context, obj *model.Todo) (*model.User, error) {
	return &model.User{ID: obj.UserID, Name: "user " + obj.UserID}, nil  //This line
}

Fix missing UserID field from model.Todo

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UserID is on input -- I don't think this should be added -- can you look again @a70537952 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tmc if I'm not wrong, this User resolver is for Query which related to model.Todo userID , nothing to do with UserID on input model.NewTodo userID

@coveralls
Copy link

Coverage Status

Coverage remained the same at 74.868% when pulling 839a842 on a70537952:master into b8ec51d on 99designs:master.

@StevenACoffman StevenACoffman merged commit 4cdf702 into 99designs:master May 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants