From 14c71e5b08730b028c212b65ee156dbcbc83578a Mon Sep 17 00:00:00 2001 From: Jaime Herencia Enjuto Date: Wed, 11 Aug 2021 19:36:14 +0200 Subject: [PATCH] added compatibility with channels 3.0 --- graphql_ws/django/routing.py | 10 +++++++++- setup.cfg | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/graphql_ws/django/routing.py b/graphql_ws/django/routing.py index 15a1356..9a7030d 100644 --- a/graphql_ws/django/routing.py +++ b/graphql_ws/django/routing.py @@ -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 @@ -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)}) diff --git a/setup.cfg b/setup.cfg index 3d07a80..29555e9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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]