samedi 28 décembre 2019

Django GraphQL endpoint testing unable to use `variables` dictionary

How to use variables in django-graphql-jwt? I can use mutation in the iGraphQL with variables normally. Then it supposed to be working as well in my 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)

Here is res.error

res.errors
Out[3]: 
[graphql.error.base.GraphQLError('Variable "$tweetId" is not defined.'),
 graphql.error.base.GraphQLError('Variable "$hidden" is not defined.')]

Workaround:
I use .format() in Python to assign value to my variable, but I don't like that hackish way

Question:
Is it bug?

Aucun commentaire:

Enregistrer un commentaire