【问题标题】:Can't use stringified JSON in graphene test不能在石墨烯测试中使用字符串化 JSON
【发布时间】: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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2018-01-11
    • 2018-03-11
    • 2020-03-23
    • 1970-01-01
    • 2017-10-26
    • 2020-01-20
    • 1970-01-01
    • 2017-05-13
    • 2017-05-11
    相关资源
    最近更新 更多