0

I am new to graphQL graphene(python). I would like to know if it is possible to create subscription root type using graphene. Thank you

Mark Chackerian
  • 21,866
  • 6
  • 108
  • 99
Bello Mayowa
  • 45
  • 2
  • 7

1 Answers1

6

It is definitely possible. You can find examples on how to do that here: https://github.com/graphql-python/graphql-ws

Here is an example from that repo:

import asyncio
import graphene


class Query(graphene.ObjectType):
    base = graphene.String()


class Subscription(graphene.ObjectType):
    count_seconds = graphene.Float(up_to=graphene.Int())

    async def resolve_count_seconds(root, info, up_to):
        for i in range(up_to):
            yield i
            await asyncio.sleep(1.)
        yield up_to


schema = graphene.Schema(query=Query, subscription=Subscription)
Yacine Filali
  • 1,762
  • 14
  • 17
  • 6
    That gives me the following error during execute: `Subscription must return Async Iterable or Observable. Received: '` – Thomas Ahle Sep 05 '18 at 13:46