【问题标题】:GraphQL queries must be stringsGraphQL 查询必须是字符串
【发布时间】: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


【解决方案1】:

我删除了 Gql 标签并按照错误消息中的说明发送了一个字符串。为我的愚蠢道歉。

【讨论】:

    猜你喜欢
    • 2018-01-13
    • 2018-12-30
    • 2019-06-09
    • 2019-06-02
    • 1970-01-01
    • 2016-08-10
    • 2022-01-18
    • 1970-01-01
    • 2019-05-23
    相关资源
    最近更新 更多