Giter Site home page Giter Site logo

Comments (3)

eamigo86 avatar eamigo86 commented on June 6, 2024

Hi @cgithinji , Can you show me your python code (models, definition of types, subscriptions, etc.) ?

from graphene-django-subscriptions.

cgithinji avatar cgithinji commented on June 6, 2024

Thanks for your reply. here is my models.py

`class Project(ValidateOnSaveMixin,models.Model):
project_code = models.CharField(unique=True, max_length=20)
name = models.CharField(max_length=45)
location = models.ForeignKey(Location, on_delete=models.CASCADE)
project_type = models.ForeignKey('ProjectType', on_delete=models.CASCADE)
project_value = models.FloatField(default=0.00)
project_status = models.ForeignKey('ProjectStatus', on_delete=models.CASCADE)
allocated_amount = models.FloatField(default=0.00)
duration_in_days = models.IntegerField()
start_date = models.DateTimeField(blank=True, null=True)
end_date = models.DateTimeField(blank=True, null=True)
project_manager = models.ForeignKey('ProjectManager', on_delete=models.CASCADE, blank=True, null=True)
vendor = models.ForeignKey(Vendor, on_delete=models.CASCADE, blank=True, null=True)
expended_amount = models.FloatField(default=0.00)
created_at = models.DateTimeField(default=timezone.now,editable=False)
updated_at = models.DateTimeField(auto_now=True,null=True)
def str (self):
return self.name
class Meta:
get_latest_by = ['-updated_at']
ordering=['-updated_at']
#
def get_projectid(self):
return self.id
def get_projects_count(self):
return Project.objects.all().count()

reversion.register(Project)
`

ProjectNode

`
class ProjectNode(DjangoObjectType):
name=graphene.String()
project_code=graphene.String()
location=graphene.Field(LocationNode)
project_type=graphene.Field(ProjectTypeNode)
project_value=graphene.Float()
project_status=graphene.Field(ProjectStatusNode)
allocated_amount=graphene.Float()
duration_in_days=graphene.Int()
start_date=graphene.types.datetime.DateTime()
end_date=graphene.types.datetime.DateTime()
project_manager=graphene.Field(ProjectManagerNode)
vendor=graphene.Field(VendorNode)
expended_amount=graphene.Float()
project_id=graphene.Int(source='get_projectid')
projects_count=graphene.String(source='get_projects_count')

class Meta:
    model=models.Project
    interfaces = (graphene.relay.Node, )
@classmethod
def get_node_from_global_id(cls, global_id, context, info, only_type=None):
    node = super().get_node_from_global_id(global_id, context, info,
                                           only_type)
    if node:
        return node

    get_node = getattr(only_type, 'get_node', None)
    if get_node:
        return get_node(global_id, context, info)

@classmethod
def to_global_id(cls, type, id):
    return id`

ProjectSubscriptions

class ProjectSubscription(Subscription): class Meta: serializer_class=ProjectSerializer stream='projects' description='Project Subscription'
corresponding serialiser class

`class ProjectSerializer(serializers.ModelSerializer):
location_id=serializers.PrimaryKeyRelatedField(queryset=Location.objects.all())
project_type_id=serializers.PrimaryKeyRelatedField(queryset=ProjectType.objects.all())
project_manager_id=serializers.PrimaryKeyRelatedField(queryset=ProjectManager.objects.all())
vendor_id=serializers.PrimaryKeyRelatedField(queryset=Vendor.objects.all())
project_status_id=serializers.PrimaryKeyRelatedField(queryset=ProjectStatus.objects.all())

class Meta:
    model = Project
    fields =('id','project_code','name','location_id','project_type_id','project_value','project_status_id','allocated_amount','duration_in_days','start_date','end_date','project_manager_id','vendor_id','expended_amount','created_at','updated_at')
    read_only=('created_at','updated_at')`

settings.py

`
GRAPHENE = {
'SCHEMA': 'djangoreactredux.schema.schema',
'SCHEMA_INDENT': 2,
'MIDDLEWARE': [
'graphene_django.debug.DjangoDebugMiddleware',
'graphene_django_subscriptions.depromise_subscription',
]
}
CHANNELS_API = {
'DEFAULT_PAGE_SIZE': 10,

}
CHANNELS_WS_PROTOCOLS = ["graphql-ws", ]
redis_host = os.environ.get('REDIS_HOST', 'localhost')
CHANNEL_LAYERS = {
"default": {
"BACKEND": "asgi_redis.RedisChannelLayer",
"CONFIG": {
"hosts": [(redis_host, 6379)],
},
"ROUTING": "djangoreactredux.routing.project_routing", # Our project routing
},
}
`
schema.py

class Subscriptions(graphene.ObjectType): project_subscription = ProjectSubscription.Field()
the error is showing up at the mixins.py deserialize function of DjangoGraphqlBindingMixin class

from graphene-django-subscriptions.

eamigo86 avatar eamigo86 commented on June 6, 2024

Please look at the garphene-django-extras documentation for greater compatibility with this subscriptions module.

from graphene-django-subscriptions.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.