4

我试图弄清楚如何使用 graphene-python 在我的模式中正确定义订阅。到目前为止,我已经实现了查询和突变,但是你如何定义一个Subscription类?

以下是我最初的想法:

class Subscription(graphene.Subscription):
  name = graphene.String()
  # rest of attributes...

  def subscribe(self, args, context, info):
    pass

有人可以提供一个小例子吗?任何帮助将不胜感激!谢谢 :)。

布赖恩

4

1 回答 1

2

因此,经过反复试验,下面的代码将适用于订阅。本质上,订阅可以被视为与查询相同。

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'
于 2017-07-21T21:53:07.737 回答