Skip to content

Bring compatibility with Channels v3 #76

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

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion graphql_ws/django/routing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from channels import __version__ as channels_version
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.sessions import SessionMiddlewareStack
from django.utils.version import get_version_tuple
from django.apps import apps
from django.urls import path
from .consumers import GraphQLSubscriptionConsumer
Expand All @@ -10,7 +12,13 @@
AuthMiddlewareStack = None


websocket_urlpatterns = [path("subscriptions", GraphQLSubscriptionConsumer)]
channels_version_tuple = get_version_tuple(channels_version)


if channels_version_tuple > (3, 0 , 0):
websocket_urlpatterns = [path("subscriptions", GraphQLSubscriptionConsumer.as_asgi())]
else:
websocket_urlpatterns = [path("subscriptions", GraphQLSubscriptionConsumer)]

application = ProtocolTypeRouter({"websocket": URLRouter(websocket_urlpatterns)})

Expand Down
6 changes: 5 additions & 1 deletion graphql_ws/django_channels.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import json

from channels.generic.websockets import JsonWebsocketConsumer
try:
# Channels version > 1 renamed the websockets module to websocket.
from channels.generic.websockets import JsonWebsocketConsumer
except ImportError:
from channels.generic.websocket import JsonWebsocketConsumer
from graphene_django.settings import graphene_settings

from .base import BaseConnectionContext
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ test =
channels==1.*; python_version<"3"
django==2.*; python_version>="3"
channels==2.*; python_version>="3"
django==3.*; python_version>="3"
channels==3.*; python_version>="3"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is it safe to assume all python >3 users will use django ?

Copy link
Member

Choose a reason for hiding this comment

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

Not sure what you mean?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I meant "will use django 3"

aiohttp; python_version>="3.5"

[bdist_wheel]
Expand Down