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

[with-apollo-auth] simplify apolloState prop (#4563)

We don't need `.data` as `apollo.cache.extract()` returns at least `{}` when cache is empty
This commit is contained in:
Brice BERNARD 2018-06-08 11:48:10 +02:00 committed by Tim Neutkens
parent e318de62c0
commit 7e8acf3a30

View file

@ -17,9 +17,7 @@ export default App => {
return class WithData extends React.Component { return class WithData extends React.Component {
static displayName = `WithData(${App.displayName})` static displayName = `WithData(${App.displayName})`
static propTypes = { static propTypes = {
apolloState: PropTypes.shape({ apolloState: PropTypes.object.isRequired
data: PropTypes.object.isRequired
}).isRequired
} }
static async getInitialProps(ctx) { static async getInitialProps(ctx) {
@ -67,7 +65,7 @@ export default App => {
} }
// Extract query data from the Apollo's store // Extract query data from the Apollo's store
const apolloState = { data: apollo.cache.extract() } const apolloState = apollo.cache.extract()
return { return {
...appProps, ...appProps,
@ -79,7 +77,7 @@ export default App => {
super(props) super(props)
// `getDataFromTree` renders the component first, the client is passed off as a property. // `getDataFromTree` renders the component first, the client is passed off as a property.
// After that rendering is done using Next's normal rendering pipeline // After that rendering is done using Next's normal rendering pipeline
this.apolloClient = initApollo(props.apolloState.data, { this.apolloClient = initApollo(props.apolloState, {
getToken: () => parseCookies().token getToken: () => parseCookies().token
}) })
} }