一个死的简单graphql客户端,支持通过websockets订阅。

py-graphql-client的Python项目详细描述


py graphql客户端

通过websocket使用graphql客户端非常简单。使用 apollo-transport-ws 协议。

示例

设置订阅超级容易

fromgraphql_clientimportGraphQLClientws=GraphQLClient('ws://localhost:8080/graphql')defcallback(_id,data):print("got new data..")print(f"msg id: {_id}. data: {data}")query="""  subscription {    notifications {      id      title      content    }  }"""sub_id=ws.subscribe(query,callback=callback)...# later stop the subscriptionws.stop_subscribe(sub_id)ws.close()

变量可以传递

fromgraphql_clientimportGraphQLClientws=GraphQLClient('ws://localhost:8080/graphql')defcallback(_id,data):print("got new data..")print(f"msg id: {_id}. data: {data}")query="""  subscription ($limit: Int!) {    notifications (order_by: {created: "desc"}, limit: $limit) {      id      title      content    }  }"""sub_id=ws.subscribe(query,variables={'limit':10},callback=callback)

正常的查询和突变也起作用

fromgraphql_clientimportGraphQLClientws=GraphQLClient('ws://localhost:8080/graphql')query="""  query ($limit: Int!) {    notifications (order_by: {created: "desc"}, limit: $limit) {      id      title      content    }  }"""res=ws.query(query,variables={'limit':10})print(res)ws.close()

待办事项

  • 当前wss不工作。支持wss。
  • 测试
  • 也支持http
  • 应该使用Asyncio WebSocket库吗?

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java提供了大量的Quartz工作线程   来自SOAPException的java抛出超时异常   java通过REST web服务同步PostgreSQL过程调用   java Hibernate:在关联表中设置值   javaimapidlechanneladapterjavax。邮政AuthenticationFailedException:[警报]同时连接太多   JavaApacheStorm:stormkafkamonitor脚本引发异常   java将jar链接到战争   Matlab与Java的集成方法   安卓公司。谷歌。ads.AdView未能实例化java。lang.ClassNotFoundException:org。json。JSONException   “String forecastStr=mForecastAdapter.getItem(position);”行中出现java错误阳光工程   java如何将Mono中的列表属性作为流量进行操作?   java DecimalFormat类不必要地给出整数   java@IfProfileValue两个spring配置文件   java如何使用SwingWorker创建多线程?   java从扩展SwingWorker的内部类触发事件   java二叉树高度实现