相关疑难解决方法(0)

如何在 grpahql 和 Strapi 中传递 JSON 对象

当我手动编写突变查询(在 graphql 插件中)时,它正在工作:

mutation {
                    createExam(input: {
                      data: {
                        name: "myName"
                        desription: "ggg"
                        questions: [{gf: "hello"}]
                        time: 2
                        subjects: ["5c468e2d61670b25b46ccdfe"]
                      }
                    }) {
                      exam {
                        name
                                desription
                        time

                      }
                    }
                  }
Run Code Online (Sandbox Code Playgroud)

但是如果我编码它并传递完全相同的数组,我会得到一个完全相同对象的数组,我得到 [null, null]

let parsedQuestion = [{gf: "hello"}];

 const response = await strapi.request('POST', '/graphql', {
            data: {
                query: `mutation {
                    createExam(input: {
                      data: {
                        name: "` + examInfo.newExamName + `"
                        desription: "` + examInfo.newExamDescription + `"
                        time: ` + Number(examInfo.newExamTime) + `,
                        questions: `+ parsedQuestion + `, 
                        subjects: ["` …
Run Code Online (Sandbox Code Playgroud)

json graphql strapi

2
推荐指数
1
解决办法
4809
查看次数

标签 统计

graphql ×1

json ×1

strapi ×1