2017-06-02 35 views
0

我从https://github.com/facebook/relay/blob/master/packages/react-relay/modern/ReactRelayPaginationContainer.js阅读并https://facebook.github.io/relay/docs/pagination-container.html即使有更多的项目,我不能做继电器loadMore?

我的计数变量是工作,我想我已经正确设置它,但我不能loadMore项目,我hasMore是假的,这意味着我没有更多的待办事项到display.This是我的代码:

export default createPaginationContainer(TodoList, 
    { 
    viewer: graphql` 
      fragment TodoList_viewer on User { 
       todos(
       first: $count # 
      ) @connection(key: "TodoList_todos") { 
       edges { 
        node { 
        id, 
        complete, 
        ...Todo_todo, 
        }, 
       }, 
       }, 
       id, 
       totalCount, 
       completedCount, 
       ...Todo_viewer, 
      } 
     `, 
    }, 
    { 
    direction: 'forward', 
    getConnectionFromProps(props) { 
     console.log("getConnectionFromProps props ",props) 
     return props.viewer && props.viewer.todos; 
    }, 
    getFragmentVariables(prevVars, totalCount) { 
     console.log("getFragmentVariables total count ",totalCount) 
     return { 
     ...prevVars, 
     count: totalCount, // the total of displayed todos on the fragment 
     }; 
    }, 
    getVariables(props, {count}, fragmentVariables) { 
     console.log("getVariables count ",count) 
     return { 
     count, 
     // cursor, 
     // in most cases, for variables other than connection filters like 
     // `first`, `after`, etc. you may want to use the previous values. 
     // orderBy: fragmentVariables.orderBy, 
     }; 
    }, 
    query: graphql` 
     query TodoListPaginationQuery(# assign component name + Pagination + Query 
     $count: Int! 
    ) { 
     viewer { 
      # You could reference the fragment defined previously. 
      ...TodoList_viewer 
     } 
     } 
    ` 
    }); 

我不知道我在做什么错在这里。也许如果你知道这个工作示例(我在github中找不到),我将非常感谢

回答

0

服务器是否正确地暴露了连接的pageInfo ?.该TodoConnection类型应具有以下领域

  1. edges: [TodoEdge]
  2. pageInfo: PageInfo!

PageInfo类型应具有以下字段:

endCursor: String 
When paginating forwards, the cursor to continue. 

hasNextPage: Boolean! 
When paginating forwards, are there more items? 

hasPreviousPage: Boolean! 
When paginating backwards, are there more items? 

startCursor: String 
When paginating backwards, the cursor to continue. 

我找不到一个例子要么但我建议你看看这些类型/领域。如果您的堆栈中安装了GraphiQL,那么您也可以尝试手动查询以放弃任何与服务器相关的问题。

+1

我explecitly所有在pageInfo,hasNextPage是真实的,但但this.props.relay.hasMore()返回false –

0

您使用的是什么版本的React-Relay?你可以尝试使用1.5.0,我面临同样的问题,但我现在无法升级1.5.0。

我认为1.5.0版本可能会解决这个问题: https://github.com/facebook/relay/releases/tag/v1.5.0

修复承诺:

  • 固定端游标时在分页集装箱的空连接
  • 取回到零个边缘
  • 修复分页
相关问题