python - 如何在 graphql-flask 中应用订阅?
问题描述
我是 GraphQL 的新手,并且在 Flask 中使用订阅。但得到错误。以下是我创建的文件。在 models.py 文件中,我有“订单”表。我无法理解在哪个文件中显示错误。如果有人知道答案,请告诉我。
应用程序.py
app = Flask(__name__)
sockets = Sockets(app)
pubsub = RedisPubsub()
CORS(app)
subscription_mgr = SubscriptionManager(schema, pubsub)
@sockets.route('/socket')
def socket_channel(websocket):
subscription_server = SubscriptionServer(subscription_mgr, websocket)
subscription_server.handle()
return []
@app.teardown_appcontext
def shutdown_session1(exception=None):
db_session_ordermanag.remove()
if __name__ == "__main__":
from geventwebsocket import WebSocketServer
server = WebSocketServer(('', 5000), app)
server.serve_forever()
订阅.py
class Subscription(graphene.ObjectType):
orders = graphene_sqlalchemy.SQLAlchemyConnectionField(
Order, active=graphene.Boolean())
def resolve_orders(self, args, context, info):
with app.app_context():
query = Order.get_query(context)
return query.filter_by(id=info.root_value.get('id'))
突变.py
class CreateOrder(graphene.ClientIDMutation):
class Input:
#id = graphene.Int()
revision = graphene.Int()
name = graphene.String()
statusid = graphene.Int()
ok = graphene.Boolean()
order = graphene.Field(lambda: Order)
@classmethod
def mutate_and_get_payload(cls, args, context, info):
_input = args.copy()
del _input['clientMutationId']
new_order = OrderModel(**_input)
db_session_pg.add(new_order)
db_session_pg.commit()
ok = True
if pubsub.subscriptions:
pubsub.publish('orders', new_order.as_dict())
return CreateOrder(ok=ok, order=new_order)
错误:
File "C:\Users\mpal\AppData\Local\Programs\Python\Python37-32\lib\site-packages\graphql\execution\executor.py", line 36, in <module>
from .middleware import MiddlewareManager
File "C:\Users\mpal\AppData\Local\Programs\Python\Python37-32\lib\site-packages\graphql\execution\middleware.py", line 73, in <module>
@promisify
File "C:\Users\mpal\AppData\Local\Programs\Python\Python37-32\lib\site-packages\promise\promise.py", line 444, in promisify
raise TypeError("Object is not a Promise like object.")
TypeError: Object is not a Promise like object.
如何解决此错误?
解决方案
推荐阅读
- c# - 使用 JSON.NET 生成截断的 JSON
- utf-8 - Unicode 和 ASCII 运算符之间的区别
- python - 在 TabbedPanel 中获取小部件/项目 ID
- .net - 如何从 .NET 中的 CultureInfo 获取 ISO 3166 国家代码
- mysql - SQL语句检查用户是否被允许
- here-maps-rest - Here XYZ Studio 的底图图层
- css - WP画廊问题,在移动设备上没有响应
- excel - VBA 没有循环播放任何 PowerPoint 幻灯片
- javascript - 如何使用自定义登录处理程序在服务器上自动登录以进行 Meteor 集成测试
- python - Python:无法使用 Beautifulsoup 获得任何输出