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

Exception inside application: No route found for path 'graphql'. #101

Open
wlodevelopteam opened this issue Mar 6, 2023 · 1 comment
Open

Comments

@wlodevelopteam
Copy link

after handshake, we got this error.
Exception inside application: No route found for path 'graphql'.

we implemented basic approach as below. whats wrong inside our approach?

### project/schema
class MySubscription(channels_graphql_ws.Subscription):
    notification_queue_limit = 64
    event = graphene.String()

    class Arguments:
        arg1 = graphene.String()
        arg2 = graphene.String()

    @staticmethod
    def subscribe(root, info, arg1, arg2):
        return ["group42"]

    @staticmethod
    def publish(payload, info, arg1, arg2):
        return MySubscription(event="Something has happened!")
    
class Subscription(graphene.ObjectType):
    my_subscription = MySubscription.Field()
### app/consumers.py
import channels_graphql_ws
from project.schema import schema

class MyGraphqlWsConsumer(channels_graphql_ws.GraphqlWsConsumer):
    schema = schema

    # send_keepalive_every = 42
    # strict_ordering = True

    async def on_connect(self, payload):
        print("New client connected!")
### project/asgi.py
import os
import channels
from django.urls import path
from django.core.asgi import get_asgi_application

from app.consumers import MyGraphqlWsConsumer

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')

django_asgi_app = get_asgi_application()

application = channels.routing.ProtocolTypeRouter({
    "http": get_asgi_application(),
    "websocket": channels.routing.URLRouter([
        path("/graphql", MyGraphqlWsConsumer),
    ])
})
@djpritchett
Copy link

djpritchett commented Aug 23, 2023

I struggled with this for too long of a time.
This is what worked for me. (notice no slashes in the graphql path)

websocket_urlpatterns = [
    django.urls.re_path(r"graphql", MyGraphqlWsConsumer.as_asgi()),
]

application = ProtocolTypeRouter({
    "http": django_asgi_app,
    "websocket": channels.auth.AuthMiddlewareStack(channels.routing.URLRouter(websocket_urlpatterns)),
})

hope it helps someone else.

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

No branches or pull requests

2 participants