0

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

4

1 回答 1

6

这绝对是可能的。您可以在此处找到有关如何执行此操作的示例: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)
于 2018-05-31T01:25:07.363 回答