【发布时间】:2018-05-24 07:14:23
【问题描述】:
我正在尝试从 GraphQL 端点获取一些数据,但是我不断收到错误消息“必须提供查询字符串”。我确定我提供了查询字符串,这个错误来自哪里?
端点是:https://antserver-blocjgjbpw.now.sh/graphql
const query = `{
ants {
name
color
length
weight
}
}`
document.getElementById("basicFetchButton").addEventListener("click", () => {
fetch("https://antserver-blocjgjbpw.now.sh/graphql", {
method: 'POST',
'Content-Type': 'application/graphql',
body: JSON.stringify({query})
})
.then(res => res.json())
.then(data => console.log(data))
})
【问题讨论】: