Skip to content

Update Apollo Example #888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jan 26, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions examples/with-apollo/lib/withData.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ export default (Component) => (
const client = initClient(headers)
const store = initStore(client, client.initialState)

const props = {
url: { query: ctx.query, pathname: ctx.pathname },
...await (Component.getInitialProps ? Component.getInitialProps(ctx) : {})
}

if (!process.browser) {
const app = (
<ApolloProvider client={client} store={store}>
<Component url={{ query: ctx.query, pathname: ctx.pathname }} />
<Component {...props} />
</ApolloProvider>
)
await getDataFromTree(app)
Expand All @@ -28,7 +33,8 @@ export default (Component) => (
data: state.apollo.data
}
},
headers
headers,
...props
}
}

Expand All @@ -41,7 +47,7 @@ export default (Component) => (
render () {
return (
<ApolloProvider client={this.client} store={this.store}>
<Component url={this.props.url} />
<Component {...this.props} />
</ApolloProvider>
)
}
Expand Down