我正在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标签是标准的吗?
谢谢您,有些帮助。
答案 0 :(得分:0)
我删除了Gql标签,并按照错误消息中的说明发送了一个字符串。抱歉,我很傻。