如何在django-graphql-jwt
中使用variables
?
我可以在iGraphQL
和variables
中正常使用mutation
。那么它应该在我的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.')]
解决方法:
我在Python
中使用.replace()
为变量赋值,但我不喜欢这种粗俗的方式
问题:
是虫子吗
目前没有回答
相关问题 更多 >
编程相关推荐