graphene-subscriptions
graphene-subscriptions copied to clipboard
Add automatic subscriptions for Django models
It would be awesome to not have to manually define created, updated and deleted subscriptions for each Django model type. Instead, we could have a DjangoModelSubscription class that takes in a DjangoObjectType as a metaclass argument and automatically defines subscriptions for each model event.
It could look something like this:
# your_app/graphql/subscriptions.py
from graphene_subscriptions.types import DjangoModelSubscription
class YourModelSubscription(DjangoModelSubscription):
class Meta:
type = YourModelType
# your_project/schema.py
import graphene
from your_app.graphql.subscriptions import YourModelSubscription
class Subscription(YourModelSubscription):
pass
class Query(graphene.ObjectType):
base = graphene.String()
schema = graphene.Schema(query=Query, subscription=Subscription)