Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
35ffad96
Commit
35ffad96
authored
Dec 18, 2017
by
Brice BERNARD
Committed by
Tim Neutkens
Dec 18, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[with-apollo] Fix missing rootContext (#3468)
parent
4a3aa261
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
9 deletions
+18
-9
Header.js
examples/with-apollo/components/Header.js
+4
-1
withData.js
examples/with-apollo/lib/withData.js
+10
-4
about.js
examples/with-apollo/pages/about.js
+2
-2
index.js
examples/with-apollo/pages/index.js
+2
-2
No files found.
examples/with-apollo/components/Header.js
View file @
35ffad96
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
>
...
...
@@ -23,3 +24,5 @@ export default ({ pathname }) => (
`
}
<
/style
>
<
/header
>
)
export
default
withRouter
(
Header
)
examples/with-apollo/lib/withData.js
View file @
35ffad96
...
...
@@ -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.
...
...
examples/with-apollo/pages/about.js
View file @
35ffad96
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
>
...
...
examples/with-apollo/pages/index.js
View file @
35ffad96
...
...
@@ -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
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment