Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[with-apollo] Fix missing rootContext #3468

Merged
merged 1 commit into from
Dec 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion examples/with-apollo/components/Header.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Link from 'next/link'
import { withRouter } from 'next/router'

export default ({ pathname }) => (
const Header = ({ router: { pathname } }) => (
<header>
<Link prefetch href='/'>
<a className={pathname === '/' ? 'is-active' : ''}>Home</a>
Expand All @@ -23,3 +24,5 @@ export default ({ pathname }) => (
`}</style>
</header>
)

export default withRouter(Header)
14 changes: 10 additions & 4 deletions examples/with-apollo/lib/withData.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,20 @@ export default ComposedComponent => {
// and extract the resulting data
if (!process.browser) {
const apollo = initApollo()
// Provide the `url` prop data in case a GraphQL query uses it
const url = { query: ctx.query, pathname: ctx.pathname }

try {
// Run all GraphQL queries
await getDataFromTree(
<ApolloProvider client={apollo}>
<ComposedComponent url={url} {...composedInitialProps} />
</ApolloProvider>
<ComposedComponent {...composedInitialProps} />
</ApolloProvider>,
{
router: {
asPath: ctx.asPath,
pathname: ctx.pathname,
query: ctx.query
}
}
)
} catch (error) {
// Prevent Apollo Client GraphQL errors from crashing SSR.
Expand Down
4 changes: 2 additions & 2 deletions examples/with-apollo/pages/about.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import App from '../components/App'
import Header from '../components/Header'

export default props => (
export default () => (
<App>
<Header pathname={props.url.pathname} />
<Header />
<article>
<h1>The Idea Behind This Example</h1>
<p>
Expand Down
4 changes: 2 additions & 2 deletions examples/with-apollo/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import Submit from '../components/Submit'
import PostList from '../components/PostList'
import withData from '../lib/withData'

export default withData(props => (
export default withData(() => (
<App>
<Header pathname={props.url.pathname} />
<Header />
<Submit />
<PostList />
</App>
Expand Down