Unverified Commit dc9e2708 authored by JJ Kasper's avatar JJ Kasper Committed by Joe Haddad

Update examples for Apollo with AppTree (#8180)

* Update examples for Apollo with AppTree

* Fix apolloClient being overwritten when rendering AppTree
parent 22aee7f2
...@@ -19,8 +19,7 @@ export default App => { ...@@ -19,8 +19,7 @@ export default App => {
static async getInitialProps (ctx) { static async getInitialProps (ctx) {
const { const {
Component, AppTree,
router,
ctx: { req, res } ctx: { req, res }
} = ctx } = ctx
const apollo = initApollo( const apollo = initApollo(
...@@ -48,14 +47,7 @@ export default App => { ...@@ -48,14 +47,7 @@ export default App => {
// and extract the resulting data // and extract the resulting data
try { try {
// Run all GraphQL queries // Run all GraphQL queries
await getDataFromTree( await getDataFromTree(<AppTree {...appProps} apolloClient={apollo} />)
<App
{...appProps}
Component={Component}
router={router}
apolloClient={apollo}
/>
)
} catch (error) { } catch (error) {
// Prevent Apollo Client GraphQL errors from crashing SSR. // Prevent Apollo Client GraphQL errors from crashing SSR.
// Handle them in components via the data.error prop: // Handle them in components via the data.error prop:
...@@ -89,7 +81,7 @@ export default App => { ...@@ -89,7 +81,7 @@ export default App => {
} }
render () { render () {
return <App {...this.props} apolloClient={this.apolloClient} /> return <App apolloClient={this.apolloClient} {...this.props} />
} }
} }
} }
...@@ -7,7 +7,7 @@ export default App => { ...@@ -7,7 +7,7 @@ export default App => {
return class Apollo extends React.Component { return class Apollo extends React.Component {
static displayName = 'withApollo(App)' static displayName = 'withApollo(App)'
static async getInitialProps (ctx) { static async getInitialProps (ctx) {
const { Component, router } = ctx const { AppTree } = ctx
let appProps = {} let appProps = {}
if (App.getInitialProps) { if (App.getInitialProps) {
...@@ -20,14 +20,7 @@ export default App => { ...@@ -20,14 +20,7 @@ export default App => {
if (typeof window === 'undefined') { if (typeof window === 'undefined') {
try { try {
// Run all GraphQL queries // Run all GraphQL queries
await getDataFromTree( await getDataFromTree(<AppTree {...appProps} apolloClient={apollo} />)
<App
{...appProps}
Component={Component}
router={router}
apolloClient={apollo}
/>
)
} catch (error) { } catch (error) {
// Prevent Apollo Client GraphQL errors from crashing SSR. // Prevent Apollo Client GraphQL errors from crashing SSR.
// Handle them in components via the data.error prop: // Handle them in components via the data.error prop:
...@@ -55,7 +48,7 @@ export default App => { ...@@ -55,7 +48,7 @@ export default App => {
} }
render () { render () {
return <App {...this.props} apolloClient={this.apolloClient} /> return <App apolloClient={this.apolloClient} {...this.props} />
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment