我有一個來自graphql查詢的「帖子」數組,我試圖在apollo docs中使用offset +極限進行分頁工作。目前按下「loadMore」更新查詢,結果爲fetchMoreResult
是正確的。此外,連接的newResults
在登錄時顯示正確。也許我做了一個不正確的假設,但我理解文檔的方式是,新生成的posts
將自動傳遞到我的TestComponent
並重新呈現。這是不正確的?Apollo fetch更新道具不重繪渲染組件
import React from 'react';
import { View, Text } from 'react-native';
import { graphql } from 'react-apollo';
import { GetPosts } from 'app/graphql';
class TestComponent extends React.Component {
render() {
// I would expect this to log the new props after press "loadMore"
console.log(this.props)
return (
<View style={{marginTop: 40}}>
<Text onPress={this.props.loadMore}>Push me</Text>
</View>
)
}
}
export default graphql(GetPosts, {
options:() => ({
variables: {
offset: 0,
limit: 1
}
}),
props: ({ ownProps, data }) => {
return {
...ownProps,
posts: data.posts,
loadMore:() => {
return data.fetchMore({
variables: {
offset: 1,
limit: 1
},
updateQuery: (previousResult, { fetchMoreResult }) => {
if (!fetchMoreResult) {
return previousResult;
}
const newResult = Object.assign({}, previousResult, {
posts: [...previousResult.posts, ...fetchMoreResult.posts]
});
console.log(newResult);
return newResult;
},
})
}
};
}
})(TestComponent);
編輯(17年4月11日) 我無法解釋我的查詢GetPosts
包括聯合類型,這似乎像它可能是問題,因爲如果我刪除,更新工作正常。我已經打開包裹的問題,希望更清晰:https://github.com/apollographql/react-apollo/issues/602
調用這個你可以嘗試一些人已經在這裏嘗試過的東西可看:https://github.com/apollographql/react-apollo/issues/549 –