Skip to content

Instantly share code, notes, and snippets.

@josemarluedke
Created April 9, 2020 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save josemarluedke/f811d5b32f1b74165923a50a6d5ccbde to your computer and use it in GitHub Desktop.
Save josemarluedke/f811d5b32f1b74165923a50a6d5ccbde to your computer and use it in GitHub Desktop.
import ApplicationInstance from '@ember/application/instance';
export function initialize(appInstance: ApplicationInstance): void {
const fastboot = appInstance.lookup('service:fastboot');
const apolloCache = appInstance.lookup('service:apollo').client.cache;
const shoebox = fastboot.get('shoebox');
if (fastboot.get('isFastBoot')) {
shoebox.put('apollo-cache', {
get cache(): unknown {
return apolloCache.extract();
}
});
} else {
const cacheContents = shoebox.retrieve('apollo-cache');
if (cacheContents && cacheContents.cache) {
apolloCache.restore(cacheContents.cache);
}
}
}
export default {
name: 'apollo-cache-shoebox',
initialize
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment