小编Yiu*_*ard的帖子

如何将变量传递到 Shopify Api Node js Grahql 客户端中的 metafieldsSet 突变?

我试图使用metafieldsSet突变来更新元字段,Shopify代码如下:

const client = new Shopify.Clients.Graphql(
        process.env.SHOP,
        process.env.PASSWORD
    )
    try {
        const metafields = await client.query({
            data: `mutation metafieldsSet($metafields: [MetafieldsSetInput!]!) {
                metafieldsSet(metafields: $metafields) {
                    userErrors {
                        field
                        message
                    }
                    metafields {
                        key
                        value
                    }
                }
            }           
            `,
            query: {
                metafields: [
                    {
                        key: 'cb_inventory',
                        namespace: 'my_fields',
                        ownerId: 'gid://shopify/ProductVariant/40576138313890',
                        type: 'number_integer',
                        value: '25',
                    },
                ],
            },
        })
        console.log(metafields)
        res.status(200).json({ values: metafields })
    } catch (error) {
        console.log(error)
        res.status(500).json(error)
    }
Run Code Online (Sandbox Code Playgroud)

但是,上述突变会返回以下错误:

Expected value to not be null
Variable …
Run Code Online (Sandbox Code Playgroud)

node.js shopify graphql

5
推荐指数
1
解决办法
1741
查看次数

标签 统计

graphql ×1

node.js ×1

shopify ×1