【发布时间】:2020-05-23 22:19:18
【问题描述】:
我正在尝试为我的一个字段(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': 'Syntax Error GraphQL (5:40) Expected :, found String ":"\n\n4: creatorId: 395549257913,\n5: questionData: "[{"title ":"这是一道试题","description":"试题说明","answers":[{"text":"Yes","point":50,"autofail":true},{"text ":"No","point":50,"autofail":false}]}]"\n ^\n6: ) {\n', 'locations': [{'line': 5, 'column': 40}]}]}
【问题讨论】:
-
您向我们展示的不是 JSON。
-
问题数据?它是字符串化的。我会更新 OP 以使其更清晰
-
看起来您在 API 调用中传递了错误的数据。但我们不知道您调用的是什么 API 或它需要什么数据,因此我们需要更多详细信息。
-
抱歉更新了 OP。 QuestionData 需要一个字符串。我有一个字符串化和转义的 JSON 结果。
标签: python graphql graphene-python graphene2