Skip to content
Open
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
3 changes: 2 additions & 1 deletion graphql_ws/django/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
from django.apps import apps
from django.urls import path
from .consumers import GraphQLSubscriptionConsumer
from .settings import graphql_ws_path

if apps.is_installed("django.contrib.auth"):
from channels.auth import AuthMiddlewareStack
else:
AuthMiddlewareStack = None


websocket_urlpatterns = [path("subscriptions", GraphQLSubscriptionConsumer)]
websocket_urlpatterns = [path(graphql_ws_path, GraphQLSubscriptionConsumer)]

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

Expand Down
3 changes: 3 additions & 0 deletions graphql_ws/django/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.conf import settings

graphql_ws_path = getattr(settings, "GRAPHQL_WS_PATH", "subscriptions")
3 changes: 2 additions & 1 deletion graphql_ws/django/templates/graphene/graphiql.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% load graphql_ws %}
<!--
The request to this GraphQL server provided the header "Accept: text/html"
and as a result has been presented GraphiQL - an in-browser IDE for
Expand Down Expand Up @@ -104,7 +105,7 @@
}
var fetcher;
if (true) {
var subscriptionsEndpoint = (location.protocol === 'http:' ? 'ws' : 'wss') + '://' + location.host + '/subscriptions';
var subscriptionsEndpoint = (location.protocol === 'http:' ? 'ws' : 'wss') + '://' + location.host + '/{% graphql_ws_get_path %}';
var subscriptionsClient = new window.SubscriptionsTransportWs.SubscriptionClient(subscriptionsEndpoint, {
reconnect: true
});
Expand Down
Empty file.
9 changes: 9 additions & 0 deletions graphql_ws/django/templatetags/graphql_ws.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django import template
from ..settings import graphql_ws_path


register = template.Library()

@register.simple_tag
def graphql_ws_get_path():
return graphql_ws_path