2017-06-02 19 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

修復承諾:

  • 固定端遊標時在分頁集裝箱的空連接
  • 取回到零個邊緣
  • 修復分頁
相關問題