API: Server Side Rendering
react-apollo provides some utilities to aid in server side rendering and store hydration. To learn how to implement server side rendering in your app, be sure to read the recipe for server side rendering. The following is simply a reference for the APIs of the methods used in server side rendering and not a tutorial teaching you how to set it up.
This function will walk through your React tree to find any components enhanced with
graphql(). It will take those components which are queries, execute the queries, and return a promise to notify you when all of the queries have been resolved. This promise resolves to no value. You will not be able to see the data returned by the queries that were found.
getDataFromTree when you render with the
react-dom/server methods like
renderToStaticMarkup the Apollo cache will be primed and your components will render with the fetched data in your cache. You may also choose to use the
renderToStringWithData() method which will call this function and then follow that with a call to
If one of the queries fails the promise won’t reject until all of the queries have either resolved or rejected. At that point we will reject the promise returned from
getDataFromTree with an error that has the property
error.queryErrors which is an array of all the errors from the queries we executed. At that point you may decide to either render your tree anyway (if so, errored components will be in a loading state), or render an error page and do a full re-render on the client.
For more information see the recipe for server side rendering.