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!
Advertisement
Answer
Thanks to the amplify team on discord for this one, in amplify-js the logic for the browser vs node check is:
const browserOrNode = () => { const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined'; const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null; return { isBrowser, isNode, }; };
The Datastore logic determines whether it’s going to spit that warning or start the subscriptions:
if (isNode) { logger.warn( 'Realtime disabled when in a server-side environment' ); } else { //#region GraphQL Subscriptions [ // const ctlObservable: Observable<CONTROL_MSG> ctlSubsObservable, // const dataObservable: Observable<[TransformerMutationType, SchemaModel, Readonly<{ // id: string; // } & Record<string, any>>]> dataSubsObservable, ] = this.subscriptionsProcessor.start(); }
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 🙂