reactjs - graphql 订阅在本机反应中作为推送通知处理
问题描述
我用 graphql-subscription 构建了一个应用程序,我的视图是关于图书列表的,所以每次我的视图将收到一本新书时,它都会实时更新我的图书列表,这部分已经可以正常工作,但我想添加同时推送通知,假设应用程序正在后台运行,如果有人在我的书单中添加了新书也应该收到推送通知,我有一个订阅,接收作为参数的 userId 以便更新只有我的书单。
是否可以将我的 graphql 订阅作为推送通知处理?
componentDidUpdate = () => {
client
.subscribe({
query: SUBSCRIPTION_BOOK_ADDED_BY_ID,
variables: {
_id: this.state.user._id,
},
})
.subscribe({
next: (data) => {
this.updateBookList(data);
},
error: (err) => {
console.log(err);
},
});
};
updateBookList = ({ data }) => {
this.setState((prevState) => ({
bookList: _.uniqBy(
[...prevState.bookList, data.bookAddedById],
'_id',
),
}));
};
*********
//SUBSCRIPTION_BOOK_ADDED_BY_ID
subscription bookAddedById($_id: ID!) {
bookAddedById(_id: $_id) {
_id
createdBy
title
area
}
}
解决方案
推荐阅读
- python - 作为第三方安装时管理命令不显示
- javascript - 如何淡入像这个网址这样的背景图像?
- linux - BlueZ 修改 LE CONNECT_REQ 超时
- ios - 即使只有一项更改,完整列表也会重新创建所有视图
- java - 如何在数据库中存储工作日数据以及开始时间和结束时间?
- python - 如何沿着由 3 个点和一个长度给出的弧移动鼠标?
- php - DateTime::setTime() 期望参数 1 为 int,给定字符串,但在尝试观察时消失
- php - 我可以设置选中或未选中的复选框来读取字符串值吗?
- jenkins - Gitlab Webhooks(同一个 repo 上有 2 个 Webhooks)
- java - Spring with MongoTemplate:java.lang.String com.mongodb.connection.ClusterSettings.getDescription()