How to make subscriptions with graphene v3
See original GitHub issueHi,
I’m trying to use subscriptions in graphene 3.
My naive example below doesn’t work. How do I do this?
Thanks, Rob
import asyncio
from datetime import datetime
from graphene import ObjectType, String, Schema, Field
class Query(ObjectType):
hello = String()
def resolve_hello(root, info):
return 'Hello, world!'
class Subscription(ObjectType):
time_of_day = Field(String)
async def resolve_time_of_day(root, info):
while True:
yield datetime.now().isoformat()
await asyncio.sleep(1)
schema = Schema(query=Query, subscription=Subscription)
async def main():
subscription = 'subscription { timeOfDay }'
result = await schema.execute_async(subscription)
async for item in result:
print(item)
asyncio.run(main())
Issue Analytics
- State:
- Created 4 years ago
- Comments:21 (10 by maintainers)
Top Results From Across the Web
Graphene 3 Queries, Mutations & Subscriptions
The query we will search tweets, the mutation will update the status, and the subscription will filter incoming tweets. If all went well...
Read more >Subscriptions - Django channels - Graphene-Python
To implement websocket-based support for GraphQL subscriptions, you'll need to do the following: Install and configure django-channels. Install and configure* a ...
Read more >Testing subscriptions using graphene.test in Python Graphene
The pre-release version of graphene (3) supports subscriptions in this way: import asyncio from datetime import datetime from graphene ...
Read more >graphene-subscriptions - PyPI
Add GraphqlSubscriptionConsumer to your routing.py file. # your_project/routing.py from ; Connect signals for any models you want to create ...
Read more >Build a GraphQL API with Subscriptions using Python, Asyncio ...
In the GraphQL schema, subscriptions are defined similarly to queries. We will have one subscription, called messages . It will take a userId ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I written this up: https://medium.com/@rob.blackbourn/graphene-3-queries-mutations-subscriptions-a699926ca469
Hi @hyusetiawan and @SenthilKumaranC
I’ve made a repo here with a working example of graphene 3 with queries, mutations, and subscriptions, using twitter as the data source.
I will write a tutorial of this fairly soon, but this may be useful to you as it is.
BTW ti uses a fork of graphene3 which includes a fix that hasn’t yet been included in a published package.
I’d appreciate any feedback you have.
Rob