【问题标题】:Shopify GraphQL Checkout Create MutationShopify GraphQL Checkout 创建突变
【发布时间】:2019-11-21 16:21:35
【问题描述】:

我无法使用 Shopify 的 Graphql API 创建结帐

我实际上是从 Shopify's Checkout Guide 中的此页面复制示例并将其粘贴到我尝试创建结帐的商店中安装的 Shopify 的 GraphiQL 应用程序中。

这是我的突变,我唯一改变的是variantId,所以它与我商店中的一个匹配:

mutation {
  checkoutCreate(input: {
    lineItems: [{ variantId: "gid://shopify/ProductVariant/46037988422", quantity: 1 }]
  }) {
    checkout {
       id
       webUrl
       lineItems(first: 5) {
         edges {
           node {
             title
             quantity
           }
         }
       }
    }
  }
}

这是我从 Shopify 得到的回复:

{
  "errors": [
    {
      "message": "Field 'checkoutCreate' doesn't exist on type 'Mutation'",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "mutation",
        "checkoutCreate"
      ],
      "extensions": {
        "code": "undefinedField",
        "typeName": "Mutation",
        "fieldName": "checkoutCreate"
      }
    }

根据 Shopify 的说法,奇怪的是 checkoutCreate 显然是一个突变。 See the link to the page here

然后我注意到,那个页面上的突变是不同的。所以我正在尝试那个版本,没有像这样的variable

mutation checkoutCreate(input: {
    lineItems: [{ variantId: "gid://shopify/ProductVariant/46037988422", quantity: 1 }]
  }) {
    checkout {
      id
    }
    checkoutUserErrors {
      code
      field
      message
    }
}

现在我得到的错误是:

{
  "errors": [
    {
      "message": "Parse error on \"input\" (INPUT) at [1, 25]",
      "locations": [
        {
          "line": 1,
          "column": 25
        }
      ]
    }
  ]
}

最后我用一个变量尝试了这个版本,它也失败了:

mutation checkoutCreate($input: CheckoutCreateInput!) {
  checkoutCreate(input: $input) {
    checkout {
      id
    }
    checkoutUserErrors {
      code
      field
      message
    }
  }
}

{
  "input": {
    lineItems: [{ variantId: "gid://shopify/ProductVariant/46037988422", quantity: 1 }]
  }
}

这里的错误是:

{
  "errors": [
    {
      "message": "Parse error on \"input\" (STRING) at [15, 3]",
      "locations": [
        {
          "line": 15,
          "column": 3
        }
      ]
    }
  ]
}

除此之外,Shopify 在他们的 GraphiQL 应用程序中有交互式文档。它没有将 checkoutCreate 列为可用突变。看这个截图:https://nimb.ws/af4iHx

【问题讨论】:

  • 我面临同样的问题。有更新吗?

标签: graphql shopify


【解决方案1】:

我相信您的输入会被解析为 JSON,因此请在测试时尝试在突变变量的嵌套属性周围加上引号。

    {
      "input": {
        "lineItems": [{ "variantId": "gid://shopify/ProductVariant/46037988422", 
                    "quantity": 1 }]
     }
   }

【讨论】:

    【解决方案2】:

    完成结账的突变仅适用于销售渠道。这些应用程序必须是公开的。因此,如果您正在创建私有应用程序,它可能无法正常工作。

    https://shopify.dev/tutorials/create-a-checkout-with-storefront-api https://shopify.dev/tutorials/authenticate-a-public-app-with-oauth#turn-an-app-into-a-sales-channel

    【讨论】:

      猜你喜欢
      • 2019-07-26
      • 1970-01-01
      • 2018-09-19
      • 2021-11-24
      • 1970-01-01
      • 1970-01-01
      • 2022-10-23
      • 2021-11-20
      • 2019-01-31
      相关资源
      最近更新 更多