Created
August 25, 2017 11:07
-
-
Save AndreiCalazans/4ddc9321d3d9c08230c3b331557544f9 to your computer and use it in GitHub Desktop.
Create Pagination Container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default createPaginationContainer(LinkList, | |
{ | |
viewer: graphql` | |
fragment LinkList_viewer on Viewer { | |
allLinks( | |
filter: $filter, | |
first: $count, | |
after: $after, | |
orderBy: createdAt_DESC | |
) @connection(key: "LinkList_allLinks") { | |
edges { | |
node { | |
...Link_link | |
} | |
} | |
pageInfo { | |
hasNextPage | |
endCursor | |
} | |
} | |
} | |
` | |
}, | |
{ | |
direction: 'forward', // forward or backward | |
query: graphql` | |
query LinkListForwardQuery( | |
$count: Int!, | |
$after: String, | |
$filter: LinkFilter, | |
) { | |
viewer { | |
...LinkList_viewer | |
} | |
} | |
`, // this query is called by the loadMore provied by relay. | |
getConnectionFromProps(props) { // the objective is to indicate to relay which connection to paginate through, only | |
// relevant when you have multiple connections on the same query/compponent. | |
return props.viewer && props.viewer.allLinks; | |
}, | |
getFragmentVariables(previousVariables, totalCount) { | |
// this defines the variables passed to the first query. | |
return { | |
...previousVariables, | |
count: totalCount, | |
} | |
}, | |
getVariables(props, paginationInfo, fragmentVariables) { | |
// this defines the variables passed to the refetched 'second query'. | |
return { | |
count: paginationInfo.count, | |
after: paginationInfo.cursor, | |
} | |
}, | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment