首页 > 解决方案 > ScriptTagInput 类型的变量 $input!提供了无效值

问题描述

如何在 JS 文件中正确地进行突变?

这是我目前在我的 JS 文件中的查询:

    const src = "https://faqapp.test/scripttags/app.js";

                axios({
                    url: "/app/graphql",
                    method: "post",
                    data: {
                        query: `mutation scriptTagCreate($input: ScriptTagInput!) {
                            scriptTagCreate(input: $input) {
                              scriptTag {
                                id
                              }
                              userErrors {
                                field
                                message
                              }
                            }
                          }`,
                        variables: {
                            input: {
                                src
                            }
                        },
                        headers: {
                            "Content-Type": "application/json"
                        }
                    }
                })
                    .then(res => {
                        console.log(res.data);
                    })
                    .catch(err => {
                        console.log(err.message);
                    });

我正在尝试执行的查询(在 graphql 资源管理器中有效):

  mutation scriptTagCreate($input: ScriptTagInput!) {
    scriptTagCreate(input: $input) {
     scriptTag {
       id
     }
     userErrors {
       field
       message
     }
  }
}

查询变量

{
  "input": {
    "src": "https://faqapp.test/createbannertemplate.js"
  }
}

我是 graphql 的新手,所以我可能缺少一些非常简单的东西。这更像是我正在开发的 shopify 应用程序。

谢谢,希望这不是太模糊。

标签: javascriptapigraphqlshopify

解决方案


推荐阅读