Guest User

Untitled

a guest
Sep 24th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. const MoreCommentsQuery = gql`
  2. query MoreComments($cursor: String) {
  3. moreComments(cursor: $cursor) {
  4. cursor
  5. comments {
  6. author
  7. text
  8. }
  9. }
  10. }
  11. `;
  12.  
  13. const CommentsWithData = () => (
  14. <Query query={CommentsQuery}>
  15. {({ data: { comments, cursor }, loading, fetchMore }) => (
  16. <Comments
  17. entries={comments || []}
  18. onLoadMore={() =>
  19. fetchMore({
  20. // note this is a different query than the one used in the
  21. // Query component
  22. query: MoreCommentsQuery,
  23. variables: { cursor: cursor },
  24. updateQuery: (previousResult, { fetchMoreResult }) => {
  25. const previousEntry = previousResult.entry;
  26. const newComments = fetchMoreResult.moreComments.comments;
  27. const newCursor = fetchMoreResult.moreComments.cursor;
  28.  
  29. return {
  30. // By returning `cursor` here, we update the `fetchMore` function
  31. // to the new cursor.
  32. cursor: newCursor,
  33. entry: {
  34. // Put the new comments in the front of the list
  35. comments: [...newComments, ...previousEntry.comments]
  36. }
  37. };
  38. }
  39. })
  40. }
  41. />
  42. )}
  43. </Query>
  44. );
Add Comment
Please, Sign In to add comment