Forked from josemarluedke/apollo-cache-shoebox.ts
Created
April 9, 2020 13:49
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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