Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Allow users to control which groups a client is added to #7

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

jaydenwindle
Copy link
Owner

@jaydenwindle jaydenwindle commented Feb 14, 2020

This PR fixes #6 by allowing users to manually control which Channel Layers groups a subscribed client is added to, and which groups subscription events are broadcast over.

The consumer instance is now passed to each subscription resolver as a the root value, and exposes a function called subscribe. When called, this function will add the currently connected client to the specified group and return an Observable of all values sent to that group.

A model mixin called SubscriptionModelMixin has been created, which uses django-lifecycle instead of Django signals to automatically trigger subscription events when model instances are created, updated, or deleted.

This PR also removes the legacy SubscriptionEvent and ModelSubscriptionEvent classes, and removes the default post_save_subscription and post_delete_subscription signal handlers, as they are no longer used.

Example:

# your_app/graphql/subscriptions.py
class MessageCreatedSubscription(graphene.ObjectType):
    message_created = graphene.Field(MessageType)
    message_updated = graphene.Field(MessageType, id=graphene.String())

    def resolve_message_created(root, info):
        return root.subscribe("messageCreated")
    
    def resolve_message_created(root, info, id):
        return root.subscribe(f"messageCreated.{id}")

# your_app/models.py
from django.db import models
from graphene_subscriptions.models import SubscriptionModelMixin

class Message(SubscriptionModelMixin, models.Model):
    # ...

This PR also fixes #8 and #2.

@jaydenwindle jaydenwindle mentioned this pull request Feb 14, 2020

subscription = """
await asyncio.sleep(0.01)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need it? It looks like we didn't need before.

@oldani
Copy link

oldani commented Apr 26, 2020

@jaydenwindle Will this get released any soon? This will come handy in a project I am working on.

@jaydenwindle
Copy link
Owner Author

Hey @oldani! Yes, I'm planning to merge this PR and release v2 as soon as I get a chance to write a v1 -> v2 migration guide for the docs, since there are several breaking changes. I've been a bit busy with other projects recently so haven't had time to finish it.

If you'd like to help with the migration guide I'd definitely accept a PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove signals dependency Scalability
3 participants