【发布时间】:2023-03-29 16:28:01
【问题描述】:
这是我的代码
在 apollo 客户端中,我使用 useMutation。
阿波罗客户
const [addTodo, { loading, error, data }] = useMutation(gql);
阿波罗服务器
Mutation: {
signUp: async (_, formSignUp, { models: { User }, res }) => {
try {
const user = new User(formSignUp);
await user.save();
const token = await user.generateAuthToken();
res.cookie("darkAmasia", token, {
httpOnly: true
});
return "string";
} catch (error) {
?????????
}
}
}
我应该在 catch 中写什么?发送消息{status:400,error:true}in useMutation 错误。
听说throw new ApolloError是用来做这些的,但是不知道怎么弄。
【问题讨论】:
标签: node.js graphql react-apollo apollo-client apollo-server