【问题标题】:Creating subscription using graphene relay使用石墨烯中继创建订阅
【发布时间】:2023-03-31 07:30:01
【问题描述】:

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

【问题讨论】:

    标签: graphql graphene-python graphql-subscriptions graphql-mutation


    【解决方案1】:

    这绝对是可能的。您可以在此处找到有关如何执行此操作的示例: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 ...>'
    猜你喜欢
    • 2017-05-13
    • 2020-03-11
    • 2020-02-15
    • 1970-01-01
    • 2018-09-19
    • 2021-08-24
    • 2020-04-09
    • 2017-05-11
    • 2022-01-24
    相关资源
    最近更新 更多