-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apollo Client 2.0 getInitialState for SSR with Next.js #2259
Comments
@jthegedus hmm this is an interesting point. I didn't expect keeping the cache reference around to be a problem but I do see that adding a quick method would be nice. How about I implement something like this: import ApolloClient from "apollo-client";
import InMemoryCache from "apollo-cache-inmemory";
const cache = new InMemoryCache();
const client = new ApolloClient({ cache });
// do some data loading things using getDataFromTree
client.cache.extract() That way |
cc @peggyrayzis for the upgrade guide / githunt work |
Keeping the cache around isn't really a problem, but if it's not necessary because of Having the cache attached to the client in that manner would be more convenient than the |
The idea was that you typically define the cache where you need to extract the data, but that may not always be the case. I think attaching it to the client and recommending that as the official way is the best / easiest bet! Thanks for the idea! |
@jthegedus updated with #2281 Both previous ways will work, but once that beta is out, you can do |
Intended outcome:
Upgrade the Next.js with-apollo example to use Apollo Client v2.0.0.
Actual outcome:
Everything works, I just would like some feedback on the method used.
Originally I followed the Apollo Client v2 upgrade guide and implemented the recommended
however found a discussion from the Apollo apollo-client-core Slack channel that said you could extract the state from the cache through the client:
Since this is simpler I've implemented the latter. The pending PR is here vercel/next.js#3029. Any comments before it gets merged on whether or not this is a valid method for grabbing the state from the cache would be good. It's much nicer to only have to export the ApolloClient object from the https://github.com/zeit/next.js/pull/3029/files#diff-5cdabd33c0ae9862f9c98f19dff96b85 file, instead of the storing and exporting the cache itself too.
Thanks for your time!
Version
The text was updated successfully, but these errors were encountered: