[英]Graphql query with $http.post does not work
对以下代码的请求一切正常,但我没有得到任何数据(只是在chrome请求的“预览”标签中说“未找到错误”)。 我在GraphiQL
尝试了相同的查询,并返回了相关数据。 我不确定我在这里缺少什么。 请指教,有点卡住。
PlayService.prototype.getPlays = function(playID) {
//The query.
const playsQuery = `query ($playid: String) {
plays(id: $playid) {
id
items {
nodes {
id
name
}
}
}
}`;
// variables to pass.
const variables = {
playid: playID
};
//The request.
const result = $http.post(
/graphql,
{
method: 'POST',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ playsQuery, variables })
}
);
return result && result.data;
};
您似乎将数据正文发送为:
{
playsQuery: "<query string>",
variables: {}
}
GraphQL规范指定对于REST上的GraphQL查询,必须遵循以下格式:
http://graphql.org/learn/serving-over-http/
{
"query": "...",
"operationName": "...",
"variables": { "myVariable": "someValue", ... }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.