【发布时间】:2017-11-20 11:23:09
【问题描述】:
我正在尝试使用 GraphQL 查询发出 POST 请求,但它返回错误 Must provide query string,即使我的请求在 PostMan 中有效。
这是我在 PostMan 中的运行方式:
这是我在应用程序中运行的代码:
const url = `http://localhost:3000/graphql`;
return fetch(url, {
method: 'POST',
Accept: 'api_version=2',
'Content-Type': 'application/graphql',
body: `
{
users(name: "Thomas") {
firstName
lastName
}
}
`
})
.then(response => response.json())
.then(data => {
console.log('Here is the data: ', data);
...
});
任何想法我做错了什么?是否可以使我通过fetch 请求传递的正文属性格式化为Text,就像我在 PostMan 请求正文中指定的那样?
【问题讨论】:
标签: javascript node.js express graphql node-fetch