func getUserFromTodo(params graphql.ResolveParams) (interface{}, error) { todo, _ := params.Source.(repository.Todo) user, err := repository.GetUser(todo.UserId) if err != nil { return nil, err } else { return user, nil } }
func getUser(params graphql.ResolveParams) (interface{}, error) { id, _ := params.Args["id"].(int) user, err := repository.GetUser(id) if err != nil { return nil, err } else { return user, nil } }
func updateUser(params graphql.ResolveParams) (interface{}, error) { id, _ := params.Args["id"].(int) user, err := repository.GetUser(id) if err != nil { return nil, err } name, ok := params.Args["name"].(string) if ok { user.Name = name } email, ok := params.Args["email"].(string) if ok { user.Email = email } err = user.Update() if err != nil { return nil, err } else { return user, nil } }