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
abe0aebc
Commit
abe0aebc
authored
Nov 16, 2017
by
Thomas Vogel
Committed by
Tim Neutkens
Nov 16, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated with-apollo example to update option API (#3296)
parent
7c9d3500
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
13 deletions
+10
-13
PostList.js
examples/with-apollo/components/PostList.js
+6
-5
Submit.js
examples/with-apollo/components/Submit.js
+4
-8
No files found.
examples/with-apollo/components/PostList.js
View file @
abe0aebc
...
@@ -67,7 +67,7 @@ function PostList ({ data: { loading, error, allPosts, _allPostsMeta }, loadMore
...
@@ -67,7 +67,7 @@ function PostList ({ data: { loading, error, allPosts, _allPostsMeta }, loadMore
return
<
div
>
Loading
<
/div
>
return
<
div
>
Loading
<
/div
>
}
}
const
allPosts
=
gql
`
export
const
allPosts
=
gql
`
query allPosts($first: Int!, $skip: Int!) {
query allPosts($first: Int!, $skip: Int!) {
allPosts(orderBy: createdAt_DESC, first: $first, skip: $skip) {
allPosts(orderBy: createdAt_DESC, first: $first, skip: $skip) {
id
id
...
@@ -81,15 +81,16 @@ const allPosts = gql`
...
@@ -81,15 +81,16 @@ const allPosts = gql`
}
}
}
}
`
`
export
const
allPostsQueryVars
=
{
skip
:
0
,
first
:
POSTS_PER_PAGE
}
// The `graphql` wrapper executes a GraphQL query and makes the results
// The `graphql` wrapper executes a GraphQL query and makes the results
// available on the `data` prop of the wrapped component (PostList)
// available on the `data` prop of the wrapped component (PostList)
export
default
graphql
(
allPosts
,
{
export
default
graphql
(
allPosts
,
{
options
:
{
options
:
{
variables
:
{
variables
:
allPostsQueryVars
skip
:
0
,
first
:
POSTS_PER_PAGE
}
},
},
props
:
({
data
})
=>
({
props
:
({
data
})
=>
({
data
,
data
,
...
...
examples/with-apollo/components/Submit.js
View file @
abe0aebc
import
{
graphql
}
from
'react-apollo'
import
{
graphql
}
from
'react-apollo'
import
gql
from
'graphql-tag'
import
gql
from
'graphql-tag'
import
{
allPosts
,
allPostsQueryVars
}
from
'./PostList'
function
Submit
({
createPost
})
{
function
Submit
({
createPost
})
{
function
handleSubmit
(
e
)
{
function
handleSubmit
(
e
)
{
...
@@ -65,14 +66,9 @@ export default graphql(createPost, {
...
@@ -65,14 +66,9 @@ export default graphql(createPost, {
props
:
({
mutate
})
=>
({
props
:
({
mutate
})
=>
({
createPost
:
(
title
,
url
)
=>
mutate
({
createPost
:
(
title
,
url
)
=>
mutate
({
variables
:
{
title
,
url
},
variables
:
{
title
,
url
},
updateQueries
:
{
update
:
(
proxy
,
{
data
:
{
createPost
}
})
=>
{
allPosts
:
(
previousResult
,
{
mutationResult
})
=>
{
const
data
=
proxy
.
readQuery
({
query
:
allPosts
,
variables
:
allPostsQueryVars
})
const
newPost
=
mutationResult
.
data
.
createPost
proxy
.
writeQuery
({
query
:
allPosts
,
data
:
{
allPosts
:
[
createPost
,
...
data
.
allPosts
]},
variables
:
allPostsQueryVars
})
return
Object
.
assign
({},
previousResult
,
{
// Append the new post
allPosts
:
[
newPost
,
...
previousResult
.
allPosts
]
})
}
}
}
})
})
})
})
...
...
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