graphene-django updated now receiving error (reading ‘SubscriptionClient’)

graphene-django updated now receiving error (reading ‘SubscriptionClient’)


0

I have a app who use graphql

so far i was with those requirements :

aniso8601==7.0.0
asgiref==3.4.1
attrs==22.1.0
boto3==1.26.13
botocore==1.29.91
certifi==2021.10.8
cffi==1.15.0
charset-normalizer==2.0.7
coreschema==0.0.4
cryptography==3.4.7
defusedxml==0.7.1
Django==3.2.8
django-classy-tags==3.0.1
django-cors-headers==3.10.0
django-graphiql==0.4.4
django-graphql-jwt==0.3.4
django-health-check==3.17.0
django-model-utils==4.2.0
django-sekizai==3.0.1
django-storages==1.13.1
docutils==0.18
exceptiongroup==1.0.1
graphene==2.1.9
graphene-django==2.15.0
graphql-core==2.3.2
graphql-relay==2.0.1
httpie==2.6.0
idna==3.3
iniconfig==1.1.1
itypes==1.2.0
Jinja2==3.0.2
jmespath==0.10.0
JSON-log-formatter==0.5.2
MarkupSafe==2.0.1
packaging==21.3
pluggy==1.0.0
promise==2.3
psycopg2-binary==2.9.3
pycparser==2.21
Pygments==2.10.0
PyJWT==2.7.0
pyparsing==3.0.9
PySocks==1.7.1
pytest==7.2.0
pytest-django==4.5.2
python-dateutil==2.8.2
python-environ==0.4.54
pytz==2021.3
requests==2.27.1
requests-toolbelt==0.9.1
Rx==1.6.1
s3transfer==0.6.0
singledispatch==3.7.0
six==1.16.0
sqlparse==0.4.2
text-unidecode==1.3
tomli==2.0.1
uritemplate==4.1.1
urllib3==1.26.7
uWSGI==2.0.21

The goal is to update Django to 4.2 at least
When i do so using the following requirements (not everything is updated so far because of the current problem)

aniso8601==9.0.1
asgiref==3.7.2
attrs==22.1.0
boto3==1.26.13
botocore==1.29.91
certifi==2021.10.8
cffi==1.15.0
charset-normalizer==2.0.7
coreschema==0.0.4
cryptography==3.4.7
defusedxml==0.7.1
Django==4.2.7
django-classy-tags==3.0.1
django-cors-headers==3.10.0
django-graphql-jwt==0.3.4
django-health-check==3.17.0
django-model-utils==4.2.0
django-sekizai==3.0.1
django-storages==1.13.1
docutils==0.18
exceptiongroup==1.0.1
graphene==3.3
graphene-django==3.1.5
graphql-core==3.2.3
graphql-relay==3.2.0
httpie==2.6.0
idna==3.3
iniconfig==1.1.1
itypes==1.2.0
Jinja2==3.0.2
jmespath==0.10.0
JSON-log-formatter==0.5.2
MarkupSafe==2.0.1
packaging==21.3
pip-review==1.3.0
pluggy==1.0.0
promise==2.3
psycopg2-binary==2.9.3
pycparser==2.21
Pygments==2.10.0
PyJWT==2.7.0
pyparsing==3.0.9
PySocks==1.7.1
pytest==7.2.0
pytest-django==4.5.2
python-dateutil==2.8.2
python-environ==0.4.54
pytz==2021.3
requests==2.27.1
requests-toolbelt==0.9.1
Rx==1.6.1
s3transfer==0.6.0
singledispatch==3.7.0
six==1.16.0
sqlparse==0.4.2
text-unidecode==1.3
tomli==2.0.1
typing_extensions==4.8.0
uritemplate==4.1.1
urllib3==1.26.7
uWSGI==2.0.21

I can’t use the sand box over localhost/graphql
and i receive this error

Uncaught TypeError: Cannot read properties of undefined (reading 'SubscriptionClient')
    at graphiql.js:99:57
    at graphiql.js:192:3

I didn’t use subscription nowhere in my code.
I don’t want to, what can i do to fix this issue ?

schema.py

import graphene
import graphql_jwt
from graphene_django import DjangoObjectType, DjangoListField
from .models import Survey, Survey_template, Phenomenon, Phenomenon_content, Phenomenon_details
import logging
from graphql_jwt.decorators import login_required


"""
This module contains the implementation of a GraphQL API for a survey app using graphene.

The module defines several object types using DjangoObjectType for querying the database,
as well as two mutations for creating and updating Survey objects.

Classes:
- SurveyType(DjangoObjectType): A GraphQL object type representing the Survey model with all its fields.
- CreationSurveyType(DjangoObjectType): A GraphQL object type representing a limited set of fields for creating Survey objects.
- Query(graphene.ObjectType): A GraphQL object type containing all available queries.
- UpdateSurvey(graphene.Mutation): A GraphQL mutation for updating Survey objects.
- CreateSurvey(graphene.Mutation): A GraphQL mutation for creating Survey objects.
- Mutation(graphene.ObjectType): A GraphQL object type containing all available mutations.


"""
logger = logging.getLogger("django")

class SurveyType(DjangoObjectType):
    """SurveyType return every field from the survey model 

    Fields : 'survey_number','fk_survey_template','ciworm_id',
                  'url_survey_slug','is_completed','lang_code_submit',
                  'lang_code_default','date_sync','date_cre','date_mod'
    """    
    class Meta:
        model = Survey
        fields = ('survey_number','fk_survey_template','ciworm_id',
                  'url_survey_slug','is_completed','lang_code_submit',
                  'lang_code_default','date_sync','date_cre','date_mod')

class SurveyTemplateType(DjangoObjectType):
    """SurveyType return every field from the survey model 

    Fields : 'fk_phenomenon','template_uuid','content_json',
                  'title','desc','date_sync','date_cre','date_mod'
    """    
    class Meta:
        model = Survey_template

        
class PhenomenonType(DjangoObjectType):
    class Meta:
        model = Phenomenon
        fields = ('id_content', 'slug', 'parent_id', 'content_type','date_sync', 'date_cre', 'date_mod')


class CreationSurveyType(DjangoObjectType):
    """CreationSurveyType give acces only to the field involved in the creation

    Fields : 'url_survey_slug'
    """    
    phenomenon = graphene.Field(PhenomenonType)

    class Meta:
        model = Survey_template
        fields = ('fk_phenomenon', 'phenomenon', 'template_uuid', 'content_json',
                  'title', 'desc', 'date_sync', 'date_cre', 'date_mod')

    def resolve_phenomenon(self, info):
        return self.fk_phenomenon

class Query(graphene.ObjectType):
    """Query containe all the query

    Options :  
        all_surveys => Get all the surveys
        get_survey => Get a survey by is survey_number(PK)
    """    
    all_surveys = DjangoListField(SurveyType)
    get_survey_by_id = DjangoListField(SurveyType,id=graphene.Int())
    all_survey_templates = DjangoListField(SurveyTemplateType)

    def resolve_get_survey_by_id(self,info,id):
        return Survey.objects.filter(survey_number=id)
    

class UpdateSurvey(graphene.Mutation):
    """Update Survey

    Returns:
        survey (Survey): return the newly updated survey
    """    
    class Arguments:
        """Required parameter
            survey_number = primary_key
            ciworm_id = int
        """        
        survey_number = graphene.ID()
        ciworm_id = graphene.UUID(required=True)
        
    survey = graphene.Field(SurveyType)
    
    @classmethod
    @login_required
    def mutate(cls, root, info, ciworm_id, survey_number):
        survey = Survey.objects.get(survey_number=survey_number)
        survey.ciworm_id = ciworm_id
        survey.save()
        # return success = True
        return UpdateSurvey(survey=survey)

class CreateSurvey(graphene.Mutation):
    """Create Survey

    Returns:
        survey (Survey): return the newly created survey
    """    
    class Arguments:
        """Required parameter
            ciworm_id = int
            template_uuid = foreign_key (Survey_template)
        """        
        ciworm_id = graphene.Int(required=True)
        template_uuid = graphene.UUID(required=True)
    
    # We use the CreationSurveyType in order to limit the returned values
    survey = graphene.Field(SurveyType)
    
    @classmethod
    @login_required
    def mutate(cls,root,info,ciworm_id,template_uuid):
        survey = Survey.objects.create(
            ciworm_id=ciworm_id,
            fk_survey_template=Survey_template.objects.get(template_uuid=template_uuid)
        )
        survey.save()
        logger.info(f"New survey created : {survey}")
        return CreateSurvey(survey=survey)

class DeleteSurveyField(graphene.Mutation):
    """Delete Survey Field

    Returns:
        success (Boolean): Indicates if the field deletion was successful
        error_message (String): Error message if the deletion failed
    """
    class Arguments:
        url_survey_slug = graphene.String(required=True)

    success = graphene.Boolean()
    error_message = graphene.String()

    @classmethod
    @login_required
    def mutate(cls, root, info, url_survey_slug):
        field_name = "incomplete_json"
        try:
            survey = Survey.objects.get(url_survey_slug=url_survey_slug)
            if hasattr(survey, field_name) and survey.is_completed and survey.incomplete_status == "finished":
                setattr(survey, field_name, {})
                survey.save()
                success = True
                error_message = None
                logger.info(f"Field '{field_name}' deleted from survey '{url_survey_slug}'")
            else:
                success = False
                if not survey.is_completed:
                    error_message = "Survey is not completed"
                    logger.warning(error_message)
                elif not survey.incomplete_status == "finished":
                    error_message = "Survey status is not finished"
                    logger.warning(error_message)
                else:
                    error_message = f"Field '{field_name}' not found in survey '{url_survey_slug}'"
                    logger.warning(error_message)

        except Survey.DoesNotExist:
            success = False
            error_message = f"Survey '{url_survey_slug}' not found"
            logger.warning(error_message)

        return cls(success=success, error_message=error_message)

class DeleteSurvey(graphene.Mutation):
    """Delete Survey

    Returns:
        success (Boolean): Indicates if the survey deletion was successful
        error_message (String): Error message if the deletion failed
    """
    class Arguments:
        url_survey_slug = graphene.String(required=True)

    success = graphene.Boolean()
    error_message = graphene.String()

    @classmethod
    @login_required
    def mutate(cls, root, info, url_survey_slug):
        try:
            survey = Survey.objects.get(url_survey_slug=url_survey_slug)
            survey.delete()
            success = True
            error_message = None
            logger.info(f"Survey '{url_survey_slug}' deleted successfully")
        except Survey.DoesNotExist:
            success = False
            error_message = f"Survey '{url_survey_slug}' not found"
            logger.warning(error_message)
        
        return cls(success=success, error_message=error_message)




class Mutation(graphene.ObjectType):
    update_survey = UpdateSurvey.Field()
    create_survey = CreateSurvey.Field()
    delete_survey_field = DeleteSurveyField.Field()
    delete_survey = DeleteSurvey.Field()

    token_auth = graphql_jwt.ObtainJSONWebToken.Field()
    


schema = graphene.Schema(query=Query, mutation=Mutation)

Try to update package one by one but the requirements for django 4.2 is to have graphene-django >3

New contributor

Freyer Von Freyer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


Load 5 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *