The example for subscriptions on the website is not working. Trying to trigger subscriptions from either postman or the built-in graphiql web app results in the following error: Cannot return null for non-nullable field Subscription.count.
In fact, I'm unable to get any subscriptions working in my web app. I've created a fresh new project and pulled down a fresh copy of strawberry-graphql
and sanic
.
Below is the sample application I'm encountering this issue.
import asyncio
import strawberry
from typing import AsyncGenerator
from sanic import Sanic
from strawberry.sanic.views import GraphQLView
@strawberry.type
class Query:
@strawberry.field
def hello(self) -> str:
return "world"
@strawberry.type
class Subscription:
@strawberry.subscription
async def count(self, target: int = 100) -> AsyncGenerator[int, None]:
for i in range(target):
yield i
await asyncio.sleep(0.5)
schema = strawberry.Schema(query=Query, subscription=Subscription)
app = Sanic(__name__)
app.add_route(GraphQLView.as_view(schema=schema, graphiql=True), "/graphql")
# Launch Application
if __name__ == '__main__':
# dev mode
app.run(dev=True)
requirement.txt
aiofiles==23.1.0
graphql-core==3.2.3
html5tagger==1.3.0
httptools==0.5.0
multidict==6.0.4
python-dateutil==2.8.2
sanic==23.3.0
sanic-routing==22.8.0
six==1.16.0
strawberry-graphql==0.193.1
tracerite==1.1.0
typing_extensions==4.7.1
websockets==11.0.3
Submitting the following query:
subscription {
count(target: 10)
}
Results in this error:
Cannot return null for non-nullable field Subscription.count.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too