【发布时间】:2019-03-25 09:59:18
【问题描述】:
当我通过这样的突变向我的后端发出请求时:
mutation{
resetPasswordByToken(token:"my-token"){
id
}
}
我收到了这样格式的回复:
{
"data": {
"resetPasswordByToken": {
"id": 3
}
}
}
对我来说,与突变命名相同的包装器对象似乎有些尴尬(并且至少是多余的)。有没有办法摆脱那个包装器,让返回的结果更干净一些?
这就是我现在定义突变的方式:
export const ResetPasswordByTokenMutation = {
type: UserType,
description: 'Sets a new password and sends an informing email with the password generated',
args: {
token: { type: new GraphQLNonNull(GraphQLString) },
captcha: { type: GraphQLString },
},
resolve: async (root, args, request) => {
const ip = getRequestIp(request);
const user = await Auth.resetPasswordByToken(ip, args);
return user.toJSON();
}
};
【问题讨论】:
标签: graphql graphql-js