Skip to content

Commit dc9e270

Browse files
ijjkTimer
authored andcommitted
Update examples for Apollo with AppTree (#8180)
* Update examples for Apollo with AppTree * Fix apolloClient being overwritten when rendering AppTree
1 parent 22aee7f commit dc9e270

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

examples/with-apollo-auth/lib/withApollo.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ export default App => {
1919

2020
static async getInitialProps (ctx) {
2121
const {
22-
Component,
23-
router,
22+
AppTree,
2423
ctx: { req, res }
2524
} = ctx
2625
const apollo = initApollo(
@@ -48,14 +47,7 @@ export default App => {
4847
// and extract the resulting data
4948
try {
5049
// Run all GraphQL queries
51-
await getDataFromTree(
52-
<App
53-
{...appProps}
54-
Component={Component}
55-
router={router}
56-
apolloClient={apollo}
57-
/>
58-
)
50+
await getDataFromTree(<AppTree {...appProps} apolloClient={apollo} />)
5951
} catch (error) {
6052
// Prevent Apollo Client GraphQL errors from crashing SSR.
6153
// Handle them in components via the data.error prop:
@@ -89,7 +81,7 @@ export default App => {
8981
}
9082

9183
render () {
92-
return <App {...this.props} apolloClient={this.apolloClient} />
84+
return <App apolloClient={this.apolloClient} {...this.props} />
9385
}
9486
}
9587
}

examples/with-apollo/lib/with-apollo-client.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default App => {
77
return class Apollo extends React.Component {
88
static displayName = 'withApollo(App)'
99
static async getInitialProps (ctx) {
10-
const { Component, router } = ctx
10+
const { AppTree } = ctx
1111

1212
let appProps = {}
1313
if (App.getInitialProps) {
@@ -20,14 +20,7 @@ export default App => {
2020
if (typeof window === 'undefined') {
2121
try {
2222
// Run all GraphQL queries
23-
await getDataFromTree(
24-
<App
25-
{...appProps}
26-
Component={Component}
27-
router={router}
28-
apolloClient={apollo}
29-
/>
30-
)
23+
await getDataFromTree(<AppTree {...appProps} apolloClient={apollo} />)
3124
} catch (error) {
3225
// Prevent Apollo Client GraphQL errors from crashing SSR.
3326
// Handle them in components via the data.error prop:
@@ -55,7 +48,7 @@ export default App => {
5548
}
5649

5750
render () {
58-
return <App {...this.props} apolloClient={this.apolloClient} />
51+
return <App apolloClient={this.apolloClient} {...this.props} />
5952
}
6053
}
6154
}

0 commit comments

Comments
 (0)