From 4d9cf1940c3349929a4d6aa582966e585536d340 Mon Sep 17 00:00:00 2001 From: Jon Espen Kvisler Date: Sun, 4 Feb 2018 12:36:35 +0100 Subject: [PATCH] [with-apollo] Use getDataFromTree in browser (#3457) * use getDataFromTree in browser * formatting * removed ssrMode argument, not needed --- examples/with-apollo/lib/withData.js | 52 ++++++++++++++-------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/examples/with-apollo/lib/withData.js b/examples/with-apollo/lib/withData.js index 6d793f5e0b1b..8c3bc8c069ab 100644 --- a/examples/with-apollo/lib/withData.js +++ b/examples/with-apollo/lib/withData.js @@ -34,37 +34,37 @@ export default ComposedComponent => { // Run all GraphQL queries in the component tree // and extract the resulting data - if (!process.browser) { - const apollo = initApollo() - - try { - // Run all GraphQL queries - await getDataFromTree( - - - , - { - router: { - asPath: ctx.asPath, - pathname: ctx.pathname, - query: ctx.query - } + const apollo = initApollo() + try { + // Run all GraphQL queries + await getDataFromTree( + + + , + { + router: { + asPath: ctx.asPath, + pathname: ctx.pathname, + query: ctx.query } - ) - } catch (error) { - // Prevent Apollo Client GraphQL errors from crashing SSR. - // Handle them in components via the data.error prop: - // http://dev.apollodata.com/react/api-queries.html#graphql-query-data-error - } + } + ) + } catch (error) { + // Prevent Apollo Client GraphQL errors from crashing SSR. + // Handle them in components via the data.error prop: + // http://dev.apollodata.com/react/api-queries.html#graphql-query-data-error + } + + if (!process.browser) { // getDataFromTree does not call componentWillUnmount // head side effect therefore need to be cleared manually Head.rewind() + } - // Extract query data from the Apollo store - serverState = { - apollo: { - data: apollo.cache.extract() - } + // Extract query data from the Apollo store + serverState = { + apollo: { + data: apollo.cache.extract() } }