【发布时间】:2019-07-26 09:16:24
【问题描述】:
我对 GraphQL 很陌生,我正在努力从前端的 API 中获取数据。
我正在使用apollo-fetch 构建查询并发出请求,即
const fetch = createApolloFetch({
uri: `${BASE_API_URL}/graphql`,
});
fetch({
query: `{
transactions(limit: 3) {
tid
terminalNo
issuerId
}
}`,
}).then(res => {
console.log('res', res);
}).catch(err => console.log(err));
我收到此错误:"Syntax Error: Expected Name, found String "query""。
奇怪的是,使用 Postman,通过几乎相同的查询,我收到了正确的数据。
这是我在邮递员上使用的查询
query {
transactions(limit: 3) {
tid
terminalNo
issuerId
}
}
我在这里做错了什么?我尝试了查询的一些变体,但结果是一样的。
【问题讨论】:
标签: graphql apollo react-apollo graphql-js