[英]Can't use stringified JSON in graphene test
I'm trying to write a test that takes in a stringified json value for one of my fields (questionData) and it's failing:我正在尝试编写一个测试,该测试为我的一个字段 (questionData) 接收字符串化的 json 值,但它失败了:
I wrote the mutation like this:我这样写突变:
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
}
}'''
But i keep getting this error:但我不断收到此错误:
{'errors': [{'message': 'Syntax Error GraphQL (5:40) Expected :, found String ":"\\n\\n4: creatorId: 395549257913,\\n5: questionData: "[{"title":"This is a test question","description":"Test question description","answers":[{"text":"Yes","point":50,"autofail":true},{"text":"No","point":50,"autofail":false}]}]"\\n ^\\n6: ) {\\n', 'locations': [{'line': 5, 'column': 40}]}]}
{'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}] }]}
Need to use double backslashes when escaping the string转义字符串时需要使用双反斜杠
https://github.com/graphql-python/graphene/issues/521 https://github.com/graphql-python/graphene/issues/521
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.