代码之家  ›  专栏  ›  技术社区  ›  Batman

无法在石墨烯测试中使用字符串化JSON

  •  0
  • Batman  · 技术社区  · 5 年前

    我正在尝试编写一个测试,为我的一个字段(questionData)接受字符串化的json值,但失败了:

            query = '''mutation {
                createScorecard(
                    name: "Test Scorecard",
                    creatorId: 395549257913,
                    questionData: "[{\"title\":\"This is a test question\",\"description\":\"Test question description\",\"answers\":[{\"text\":\"Yes\",\"point\":50,\"autofail\":true},{\"text\":\"No\",\"point\":50,\"autofail\":false}]}]"
                ) {
                    scorecard {
                        name
                    }
                    error
                }
            }'''
    

    {'errors':[{'message':'语法错误图形QL(5:40)应为:,找到字符串:“\n\n4:creatorId:395549257913,\n5:questionData:[{“title”:“这是一个测试问题”,“description”:“测试问题描述”,“答案”:[{“text”:“Yes”,“point”:50,“autofail”:true},{“text”:“No”,“point”:50,“autofail”:false}]]]]\n^n6:){\n,“位置”:[{line:5,“column:40}]}

    0 回复  |  直到 5 年前
        1
  •  1
  •   Daniel Rearden    5 年前

    转义字符串时需要使用双反斜杠

    https://github.com/graphql-python/graphene/issues/521

    推荐文章