提交 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 => { ...@@ -20,11 +20,7 @@ export default ComposedComponent => {
static async getInitialProps(ctx) { static async getInitialProps(ctx) {
// Initial serverState with apollo (empty) // Initial serverState with apollo (empty)
let serverState = { let serverState
apollo: {
data: {}
}
}
// Evaluate the composed component's getInitialProps() // Evaluate the composed component's getInitialProps()
let composedInitialProps = {} let composedInitialProps = {}
...@@ -38,15 +34,14 @@ export default ComposedComponent => { ...@@ -38,15 +34,14 @@ export default ComposedComponent => {
try { try {
// Run all GraphQL queries // Run all GraphQL queries
await getDataFromTree( await getDataFromTree(
<ApolloProvider client={apollo}> <ComposedComponent ctx={ctx} {...composedInitialProps} />,
<ComposedComponent {...composedInitialProps} />
</ApolloProvider>,
{ {
router: { router: {
asPath: ctx.asPath, asPath: ctx.asPath,
pathname: ctx.pathname, pathname: ctx.pathname,
query: ctx.query query: ctx.query
} },
client: apollo
} }
) )
} catch (error) { } catch (error) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册