【发布时间】:2023-03-31 07:30:01
【问题描述】:
我是 graphQL 石墨烯(python)的新手。我想知道是否可以使用石墨烯创建 subscription 根类型。谢谢你
【问题讨论】:
标签: graphql graphene-python graphql-subscriptions graphql-mutation
我是 graphQL 石墨烯(python)的新手。我想知道是否可以使用石墨烯创建 subscription 根类型。谢谢你
【问题讨论】:
标签: graphql graphene-python graphql-subscriptions graphql-mutation
这绝对是可能的。您可以在此处找到有关如何执行此操作的示例: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)
【讨论】:
Subscription must return Async Iterable or Observable. Received: <async_generator object ... at ...>'