Skip to content

Commit

Permalink
[with-apollo] Use getDataFromTree in browser (#3457)
Browse files Browse the repository at this point in the history
* use getDataFromTree in browser

* formatting

* removed ssrMode argument, not needed
  • Loading branch information
jonespen authored and timneutkens committed Feb 4, 2018
1 parent 97cf428 commit 4d9cf19
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions examples/with-apollo/lib/withData.js
Expand Up @@ -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(
<ApolloProvider client={apollo}>
<ComposedComponent {...composedInitialProps} />
</ApolloProvider>,
{
router: {
asPath: ctx.asPath,
pathname: ctx.pathname,
query: ctx.query
}
const apollo = initApollo()
try {
// Run all GraphQL queries
await getDataFromTree(
<ApolloProvider client={apollo}>
<ComposedComponent {...composedInitialProps} />
</ApolloProvider>,
{
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()
}
}

Expand Down

0 comments on commit 4d9cf19

Please sign in to comment.