【发布时间】:2018-01-28 22:47:13
【问题描述】:
我正在尝试使用服务器上的 Express + Mongoose 和客户端上的 React + Apollo 从 Rest API 迁移到 GraphQL。
async resolve(_, { email, password, passwordConfirmation }) { // Sign Up mutation
const user = new User({ email });
user.password = password;
user.passwordConfirmation = passwordConfirmation;
try{
const createdUser = await user.save();
return createdUser;
} catch(error) {
console.log(error); // Returns errors object like {email: {message: 'E-mail is required'}}
throw new Error(error); // But on the client there is a string with all errors
}
}`
如何处理客户端的整个错误对象?
【问题讨论】:
标签: javascript reactjs graphql apollo