0

我正在尝试编写一个测试,该测试为我的一个字段(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': '语法错误 GraphQL (5:40) 预期 :, 找到字符串 ":"\n\n4: creatorId: 395549257913,\n5: questionData: "[{"title":"这是一道试题","description":"试题说明","answers":[{"text":"Yes","point":50,"autofail":true},{"text":"否","point":50,"autofail":false}]}]"\n ^\n6: ) {\n', 'locations': [{'line': 5, 'column': 40}] }]}

4

1 回答 1

1

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

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

于 2020-02-07T19:39:24.737 回答