【发布时间】:2020-01-26 00:50:31
【问题描述】:
我正在 Express 后端编写数据获取服务。它需要从 graphQL 端点获取数据。
我收到以下错误。我知道这是对问题的描述,但我不明白。
'GraphQL queries must be strings. It looks like you\\'re sending the internal graphql-js representation of a parsed query in your request instead of a request in the GraphQL query language. You can convert an AST to a string using the `print` function
from `graphql`, or use a client like `apollo-client` which converts the internal representation to a string for you.' }
这是我正在使用的功能:
fetchMultipleProducts(first : Number, offset : number){
fetch({
query: gql`
query {
getProduct(query: {}, first : ${first}, offset : ${offset}) {
id
code
}
}
`
})
.then(res => {
Logger.info("Fetched data");
console.log(res);
return res;
})
.catch(err => {
Logger.error("Failed to fetch", err);
});
我正在尝试将变量传递给它,我认为这是允许的?并且使用 Gql 标签是标准的吗?
我们将不胜感激,谢谢大家。
【问题讨论】:
标签: express graphql-js