Skip to content

add compatibility with channels 3 #74

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
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"
aiohttp; python_version>="3.5"

[bdist_wheel]
Expand Down