提交 cd1d9e0c 编写于 作者: S Shaleen Jain 提交者: Tim Neutkens

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)
上级 c73f7d6a
......@@ -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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册