python - Django GraphQL 端点测试无法使用“变量”字典
问题描述
怎么variables
用django-graphql-jwt
?我可以mutation
在iGraphQL
with中variables
正常使用。然后它应该在我的TestCase
from django.contrib.auth import get_user_model
from graphql_jwt.testcases import JSONWebTokenTestCase
from model_mommy import mommy
from multy_herr.commons.tests import JCMixin
from multy_herr.objections.models import Objection
from multy_herr.tweets.models import Tweet
User = get_user_model()
class UsersTest(JCMixin, JSONWebTokenTestCase):
def setUp(self) -> None:
super().setUp()
mommy.make(Objection, _quantity=3)
def test_authorized_user_hide_success(self):
"""
Hide success
:return:
"""
tweet = Tweet.objects.first()
query: str = '''
mutation{
objection(input: {
tweet: $tweetId
hidden: $hidden
}){
id
hidden
report
tweet
errors{
field
messages
}
}
}
'''
variables = {
'tweetId': str(tweet.id),
'hidden': True,
}
self.client.authenticate(self.jc)
res = self.client.execute(query, variables)
这是res.error
res.errors
Out[3]:
[graphql.error.base.GraphQLError('Variable "$tweetId" is not defined.'),
graphql.error.base.GraphQLError('Variable "$hidden" is not defined.')]
解决方法:
我使用.replace()
inPython
为我的变量赋值,但我不喜欢那种骇人听闻的方式
问:
是bug吗?
解决方案
推荐阅读
- vue.js - 如何更改元素 UI 表中特定行的样式
- xquery - 无法编译 xquery : err:XPST0003 地图表达式中不再接受 ':=' 表示法
- android-room - 如何改造和房间处理嵌套对象
- powershell - 用于搜索文件夹的 Powershell 脚本删除它们创建包含特定数据的日志文件
- java - Http Ok3 返回两个响应
- c# - 不知何故,我的值永远不会等于 1,这是有原因的吗?
- javascript - 无法在我的应用程序中找到下拉输入字段的元素
- c - 将一个字节复制到 GNU C 内联汇编中的另一个寄存器,其中编译器为两个操作数选择寄存器
- php - 如何在 JSON 中计算相同的数据?
- flutter - 热重载后会显示标记,但按下按钮时不会显示。(颤振 - 谷歌地图)