使用石墨烯中继创建订阅

Creating subscription using graphene relay

我是 graphQL 石墨烯的新手 (python)。我想知道是否可以使用石墨烯创建 subscription 根类型。谢谢

绝对有可能。您可以在此处找到有关如何执行此操作的示例:https://github.com/graphql-python/graphql-ws

这是该回购协议中的一个示例:

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)