From cd1d9e0c35a5623d3d252917313d43b956e7ead1 Mon Sep 17 00:00:00 2001 From: Shaleen Jain Date: Fri, 16 Mar 2018 16:22:30 +0530 Subject: [PATCH] with-apollo: Improve lib/withData (#3973) * pass down getInitialProps ctx to ComposedComponent * pass apollo client instance directly to getDataFromTree instead of through the ApolloProvider wrapper. * Avoid redundant empty serverState initialization (It's always initialized) --- examples/with-apollo/lib/withData.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/examples/with-apollo/lib/withData.js b/examples/with-apollo/lib/withData.js index 8c3bc8c069..d854618af7 100644 --- a/examples/with-apollo/lib/withData.js +++ b/examples/with-apollo/lib/withData.js @@ -20,11 +20,7 @@ export default ComposedComponent => { static async getInitialProps(ctx) { // Initial serverState with apollo (empty) - let serverState = { - apollo: { - data: {} - } - } + let serverState // Evaluate the composed component's getInitialProps() let composedInitialProps = {} @@ -38,15 +34,14 @@ export default ComposedComponent => { try { // Run all GraphQL queries await getDataFromTree( - - - , + , { router: { asPath: ctx.asPath, pathname: ctx.pathname, query: ctx.query - } + }, + client: apollo } ) } catch (error) { -- GitLab