1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

[with-apollo] simplify apolloState prop (#4755)

As seen on `with-apollo-auth` there are some things that need to be addressed here too.

* #4554 remove useless `apolloState` from App props on `getDataFromTree`
* #4563 simplify `apolloState` prop

Let me know if further changes/fixes are needed. 
Thank you 🎉
This commit is contained in:
Kenneth Luján Rosas 2018-07-12 11:59:28 -05:00 committed by Tim Neutkens
parent 1a3f950777
commit dca2ca6f2b

View file

@ -13,8 +13,6 @@ export default (App) => {
appProps = await App.getInitialProps(ctx)
}
const apolloState = {}
// Run all GraphQL queries in the component tree
// and extract the resulting data
const apollo = initApollo()
@ -26,7 +24,6 @@ export default (App) => {
{...appProps}
Component={Component}
router={router}
apolloState={apolloState}
apolloClient={apollo}
/>
)
@ -40,13 +37,11 @@ export default (App) => {
// getDataFromTree does not call componentWillUnmount
// head side effect therefore need to be cleared manually
Head.rewind()
// Extract query data from the Apollo store
apolloState.data = apollo.cache.extract()
} else {
apolloState.data = {}
}
// Extract query data from the Apollo store
const apolloState = apollo.cache.extract()
return {
...appProps,
apolloState
@ -55,7 +50,7 @@ export default (App) => {
constructor (props) {
super(props)
this.apolloClient = initApollo(props.apolloState.data)
this.apolloClient = initApollo(props.apolloState)
}
render () {