mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
with-apollo: Improve lib/withData (#3973)
* pass down getInitialProps ctx to ComposedComponent * pass apollo client instance directly to getDataFromTree instead of through the ApolloProvider wrapper. * Avoid redundant empty serverState initialization (It's always initialized)
This commit is contained in:
parent
c73f7d6ace
commit
cd1d9e0c35
|
@ -20,11 +20,7 @@ export default ComposedComponent => {
|
|||
|
||||
static async getInitialProps(ctx) {
|
||||
// Initial serverState with apollo (empty)
|
||||
let serverState = {
|
||||
apollo: {
|
||||
data: {}
|
||||
}
|
||||
}
|
||||
let serverState
|
||||
|
||||
// Evaluate the composed component's getInitialProps()
|
||||
let composedInitialProps = {}
|
||||
|
@ -38,15 +34,14 @@ export default ComposedComponent => {
|
|||
try {
|
||||
// Run all GraphQL queries
|
||||
await getDataFromTree(
|
||||
<ApolloProvider client={apollo}>
|
||||
<ComposedComponent {...composedInitialProps} />
|
||||
</ApolloProvider>,
|
||||
<ComposedComponent ctx={ctx} {...composedInitialProps} />,
|
||||
{
|
||||
router: {
|
||||
asPath: ctx.asPath,
|
||||
pathname: ctx.pathname,
|
||||
query: ctx.query
|
||||
}
|
||||
},
|
||||
client: apollo
|
||||
}
|
||||
)
|
||||
} catch (error) {
|
||||
|
|
Loading…
Reference in a new issue