电子在服务器端环境中的“实时禁用” AppSync“实时禁用”
我正在我的电子应用中使用Amplify AppSync,除了实时事件外,所有工作都可以使用,这意味着当数据在云中更改时,我的应用不会发出信号。
我知道这是因为它在节点中运行,这就是Amplify正在寻找的(js.browserornode),但是我不知道如何修复它。有人可以建议我如何获得实时更新吗?当我查询时,除非我dataStore.stop()和datastore.start(),否则它只是获取本地数据,但肯定有更好的方法?
先感谢您!
I'm using amplify appsync in my electron app and all works except for the realtime events which means my app doesn't get signalled when the data changes in the cloud.
I know this is because it's running in Node which is what amplify is looking for (JS.browserOrNode) however I don't know how to fix it. Can someone advise me how I can get the realtime updates? When I query it just gets the local data unless I Datastore.stop() and Datastore.start() but surely there's a better way?
Thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
多亏了Discord上的Amplify团队,在Amplify-js中,浏览器与节点检查的逻辑是:
存储逻辑确定它是否会吐出警告或启动订阅
数据 .js环境,这就是为什么数据存储在实时禁用。
您可以通过强制介绍为false,然后实时与Electron一起使用:)
Thanks to the amplify team on discord for this one, in amplify-js the logic for the browser vs node check is:
The Datastore logic determines whether it's going to spit that warning or start the subscriptions:
But because Electron runs the app in a Node.js environment it's why DataStore is disabling realtime.
You can stop this by forcing isNode to be false and then realtime works with electron :)
感谢 @s.mac,
更澄清的是S.Mac回答我如何修复我的。
打开软件包。
install patch-package
npm i Patch-package
或npm i- -save-dev补丁包
如果您喜欢
打开“ node_module/@aws-amplify/core/core/lib-ems/js.js”,然后向下滚动至
中替换所有语句
导出const browserornode =()=> {}
函数如果您使用的是TS,然后将语句更改为:npx patch-package aws-amplify
确保您已连接到Internet ,我不知道为什么。希望这对某人和我有帮助。
Thank @S.Mac,
A more clarification on S.Mac answer how I fixed mine.
Open package.json and add
"postinstall": "patch-package"
toscript
Install patch-package
npm i patch-package
ornpm i --save-dev patch-package
if you prefer
Open "node_module/@aws-amplify/core/lib-ems/JS.js" and scroll down to
and replace all the statement in with
export const browserOrNode = () => {}
function if you're using TS and change the statement in to:npx patch-package aws-amplify
ensure you're connected to internet, i don't know why.Hope this will be helpfull to someone and me.