使用石墨烯和 Python 的订阅示例 class
Example of Subscription class using Graphene and Python
我试图找出如何使用石墨烯在我的模式中正确定义订阅-python。到目前为止,我已经实现了查询和突变,但是如何定义 Subscription
class?
下面是我最初的想法:
class Subscription(graphene.Subscription):
name = graphene.String()
# rest of attributes...
def subscribe(self, args, context, info):
pass
有人可以提供一个小例子吗?任何帮助将不胜感激!谢谢 :).
布莱恩
经过反复试验,下面的代码将适用于订阅。本质上,订阅可以被视为与查询相同。
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'
我试图找出如何使用石墨烯在我的模式中正确定义订阅-python。到目前为止,我已经实现了查询和突变,但是如何定义 Subscription
class?
下面是我最初的想法:
class Subscription(graphene.Subscription):
name = graphene.String()
# rest of attributes...
def subscribe(self, args, context, info):
pass
有人可以提供一个小例子吗?任何帮助将不胜感激!谢谢 :).
布莱恩
经过反复试验,下面的代码将适用于订阅。本质上,订阅可以被视为与查询相同。
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'