graphql - Shopify GraphQL Checkout 创建突变
问题描述
我无法使用 Shopify 的 Graphql API 创建结帐
我实际上是从Shopify 的结帐指南中的此页面复制示例并将其粘贴到我尝试创建结帐的商店中安装的 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"
}
}
checkoutCreate
据 Shopify称,奇怪的是,这显然是一种突变。请参阅此处的页面链接
然后我注意到,该页面上的突变是不同的。所以我正在尝试那个版本,没有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
解决方案
完成结账的突变仅适用于销售渠道。这些应用程序必须是公开的。因此,如果您正在创建私有应用程序,它可能无法正常工作。
https://shopify.dev/tutorials/create-a-checkout-with-storefront-api https://shopify.dev/tutorials/authenticate-a-public-app-with-oauth#turn-an-app-into -销售渠道
推荐阅读
- java - 为什么 Spring OAuth 在 Google 登录后显示一个数字作为用户名?
- http - mdaemon 未知的 caldav 客户端
- javascript - 作为变量的函数
- javascript - 使用生成器和承诺时传播异常
- angular - 执行 EventEmitter 的不同方法 - Angular
- jestjs - 如何使用 toThrow() 开玩笑
- php - 未定义索引:GET 请求
- python - 什么是 Python 中 Matlab 的 cwtft() 的等价物?(连续 morlet 小波变换)
- docker - “EACCESS:权限被拒绝”,Webpack 在 Docker 容器中运行,在 dockerfile 中设置了 USER
- java - 使用反射从scala调用java类