我是graphQL graphene(python)的新手。我想知道是否可以使用石墨烯创建订阅根类型。谢谢
答案 0 :(得分:2)
绝对有可能。您可以在此处找到有关如何执行此操作的示例: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)