question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to make subscriptions with graphene v3

See original GitHub issue

Hi,

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:closed
  • Created 4 years ago
  • Comments:21 (10 by maintainers)

github_iconTop GitHub Comments

4reactions
rob-blackbourncommented, Oct 7, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found