首页 > 解决方案 > `graphene_django` 的`op_name` 参数

问题描述

django 石墨烯文档显示了一个这样的测试示例:

class MyFancyTestCase(GraphQLTestCase):
    def test_some_query(self):
        response = self.query(
            '''
            query {
                myModel {
                    id
                    name
                }
            }
            ''',
            op_name='myModel'
        )

        content = json.loads(response.content)

        # This validates the status code and if you get errors
        self.assertResponseNoErrors(response)

        # Add some more asserts if you like
        ...

他们没有任何关于什么op_name是什么以及我们应该将其设置为什么的 API 文档。我试图将其设置为我的查询名称,但得到错误:

[{'message': 'Unknown operation named "myQuery".'}]

标签: djangographene-pythongraphene-django

解决方案


仅当查询字符串中有多个操作时才需要操作名称。您只有一项操作,因此默认(无)就可以了。

https://docs.graphene-python.org/en/latest/execution/execute/#operation-name


推荐阅读