-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
I have followed the instructions in the README step by step as well as the tutorial on the apollo client subscriptions part (https://www.apollographql.com/docs/react/data/subscriptions/):
const httpLink = new HttpLink({
uri: "http://localhost:8000/graphql/", // use https for secure endpoint
});
// Create a WebSocket link:
const wsLink = new WebSocketLink({
uri: "ws://localhost:8000/graphql/", // use wss for a secure endpoint
options: {
reconnect: true
}
});
// using the ability to split links, you can send data to each link
// depending on what kind of operation is being sent
const link = split(
// split based on operation type
({ query }) => {
const { kind, operation } = getMainDefinition(query);
return kind === 'OperationDefinition' && operation === 'subscription';
},
wsLink,
httpLink,
);
However, when trying to perform a subscription:
subscription onMessageCreated{
messageCreated{
id
content
}
}
I get the following error:
api_1 | INFO django.channels.server WebSocket HANDSHAKING /graphql/ [172.19.0.1:41526] [PID:41:django-main-thread]
api_1 | INFO django.channels.server WebSocket HANDSHAKING /graphql/ [172.19.0.1:41526] [PID:41:django-main-thread]
api_1 | INFO django.channels.server WebSocket CONNECT /graphql/ [172.19.0.1:41526] [PID:41:django-main-thread]
api_1 | INFO django.channels.server WebSocket CONNECT /graphql/ [172.19.0.1:41526] [PID:41:django-main-thread]
api_1 | ERROR daphne.server Exception inside application: 'NoneType' object has no attribute 'execute' [PID:41:django-main-thread]
api_1 | Traceback (most recent call last):
api_1 | File "/usr/local/lib/python3.8/site-packages/channels/consumer.py", line 58, in __call__
api_1 | await await_many_dispatch(
api_1 | File "/usr/local/lib/python3.8/site-packages/channels/utils.py", line 51, in await_many_dispatch
api_1 | await dispatch(result)
api_1 | File "/usr/local/lib/python3.8/site-packages/asgiref/sync.py", line 423, in __call__
api_1 | ret = await asyncio.wait_for(future, timeout=None)
api_1 | File "/usr/local/lib/python3.8/asyncio/tasks.py", line 455, in wait_for
api_1 | return await fut
api_1 | File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
api_1 | result = self.fn(*self.args, **self.kwargs)
api_1 | File "/usr/local/lib/python3.8/site-packages/channels/db.py", line 14, in thread_handler
api_1 | return super().thread_handler(loop, *args, **kwargs)
api_1 | File "/usr/local/lib/python3.8/site-packages/asgiref/sync.py", line 462, in thread_handler
api_1 | return func(*args, **kwargs)
api_1 | File "/usr/local/lib/python3.8/site-packages/channels/consumer.py", line 105, in dispatch
api_1 | handler(message)
api_1 | File "/usr/local/lib/python3.8/site-packages/graphene_subscriptions/consumers.py", line 60, in websocket_receive
api_1 | result = schema.execute(
api_1 | AttributeError: 'NoneType' object has no attribute 'execute'
api_1 | INFO django.channels.server WebSocket DISCONNECT /graphql/ [172.19.0.1:41526] [PID:41:django-main-thread]
api_1 | INFO django.channels.server WebSocket DISCONNECT /graphql/ [172.19.0.1:41526] [PID:41:django-main-thread]
Might any of you know why this error occurs? I am quite new to subscriptions/asgi/apollo
Normal queries/mutations still work fine
EDIT: maybe the problem is in the routing?
My urls.py looks like this:
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.contrib.staticfiles.views import serve
from django.views.decorators.csrf import csrf_exempt
from .data_feeds.urls import urlpatterns as feed_urls
from .graphql.api import schema
from .graphql.views import GraphQLView
from .product.views import digital_product
urlpatterns = [
url(r"^graphql/", csrf_exempt(GraphQLView.as_view(schema=schema)), name="api"),
url(r"^feeds/", include((feed_urls, "data_feeds"), namespace="data_feeds")),
url(
r"^digital-download/(?P<token>[0-9A-Za-z_\-]+)/$",
digital_product,
name="digital-product",
),
]
while for the asgi I have followed the instructions and created this asgi.py
import os
from channels.routing import ProtocolTypeRouter, URLRouter
from django.core.asgi import get_asgi_application
from django.urls import path
from django.conf.urls import url
from graphene_subscriptions.consumers import GraphqlSubscriptionConsumer
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'saleor.settings')
application = ProtocolTypeRouter({
#"http": get_asgi_application(),
"websocket": URLRouter([
path("graphql/", GraphqlSubscriptionConsumer)
#url(r"^graphql/", GraphqlSubscriptionConsumer)
]),
# Just HTTP for now. (We can add other protocols later.)
})
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels