【发布时间】:2019-06-28 15:55:43
【问题描述】:
我正在使用 GraphQL 连接到多个 RESTful 端点。我正在编写一个突变来更新用户详细信息,但是 GraphiQL 显示以下响应为 null 而不是更新的用户 ID 和名称...
{
"data": {
"updateUser": null
}
}
updateUser: (parent, args) => {
const { id, name } = args;
return fetch(`${url}/users/${id}`, {
method: 'PUT',
body: JSON.stringify({ id, name }),
headers: { 'Content-Type': 'application/json' },
})
.then(res => res.json())
.then(json => console.log(json));
},
提前致谢。
【问题讨论】:
-
摆脱
.then(json => console.log(json))。console.log没有返回值。 -
请参阅this answer 中的常见场景#5。
标签: javascript rest graphql