【发布时间】: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
【问题讨论】:
-
我面临同样的问题。有更新吗?