Express GraphQL查询必须是字符串
我正在Express后端编写一个数据获取服务。它需要从graphQL端点获取数据 我得到以下错误。我知道这是对问题的描述,但我不明白Express GraphQL查询必须是字符串,express,graphql-js,Express,Graphql Js,我正在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 lan
'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标记是标准的吗
非常感谢大家的帮助。我删除了Gql标记,并按照错误消息中的说明发送了一个字符串。为我的愚蠢道歉 FWIW,你可能应该。