【问题标题】:Use variables in Shopify Bulk Operations graphql mutation在 Shopify 批量操作中使用变量 graphql 突变
【发布时间】:2021-11-20 01:02:09
【问题描述】:

我正在尝试使用 graphql 在批量操作中查询商店的订单。我在 graphql 请求中使用 tags 变量来查询带有特定标签的订单。为了做到这一点,我一直在关注 Shopify 的 documentation

这是我一直在尝试的:

const variables = {
  "tags": "tag:foo AND tag:bar"
};

const query = gql`
  mutation getOrders($tags: String!) {  
    bulkOperationRunQuery(
      query:"""
        query {
          orders(query: $tags) {
            edges {
              node {
                id
                email
              }
            }
          }
        }
      """
    ) {
      bulkOperation {
        id
        url
        status
      }
      userErrors {
        field
        message
      }
    }
  }
`;

const bulkOperation = await graphQLClient.request(query, variables);

但是,我总是从 api 得到这个错误:

Variable $tags is declared by getOrders but not used

有谁知道是否有办法在批量操作中使用 graphql 变量?谢谢!

【问题讨论】:

    标签: graphql shopify graphql-js shopify-app shopify-api


    【解决方案1】:

    """ 是基于文档的多行字符串,这意味着它只是一个字符串,不允许使用任何变量。您可以在模板化字符串中使用 js 变量替换,如 ${tags} 并一起绕过这一切,或者尝试连接是否有效比如 """ 第一部分 """" + $tags + """ 第二部分 """

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-17
      • 2018-07-27
      • 2017-03-18
      • 1970-01-01
      • 2019-11-21
      • 1970-01-01
      • 2018-09-22
      • 2019-11-19
      相关资源
      最近更新 更多