我试图弄清楚如何使用graphene-python在我的模式中正确地定义订阅。到目前为止,我已经实现了查询和突变,但是如何定义Subscription类呢?
以下是我最初的想法:
class Subscription(graphene.Subscription):
name = graphene.String()
# rest of attributes...
def subscribe(self, args, context, info):
pass有没有人能举个小例子?任何帮助都将不胜感激!谢谢你:)。
布赖恩
发布于 2017-07-22 05:53:08
因此,经过一些试验和错误,下面的代码将适用于订阅。从本质上讲,可以将订阅视为查询。
class Subscription(graphene.ObjectType):
# Define subscription attributes, i.e. what you want the user to subscribe to.
# This part will most likely be defined by your schema.
subscription_attr = graphene.Int()
def resolve_events_count(self, args, context, info):
## define resolver function once UI provides subscription data...
return 'Value here defined as graphene class'https://stackoverflow.com/questions/44732008
复制相似问题