我的 Feed 组件中有以下中继容器,它是一个简单的帖子列表
export default Relay.createContainer(Feed, {
initialVariables: {
count: 5,
},
fragments: {
viewer: () => Relay.QL`
fragment on Viewer {
posts(first: $count) {
pageInfo {
hasNextPage
}
edges {
node {
id,
body
},
},
},
},
`,
},
});
这些帖子是按最新帖子组织的,我如何检查我的 graphql 服务器中是否有较新的帖子?我想要执行拉动策略,直到将其迁移到 graphql/relay 订阅
我可以使用forceFetch吗?我不想更新 Relay Store,我只是想通知有新帖子的用户
最佳答案
我能想到的一种方法是拥有一个提供最新时间戳的端点。例如,此端点返回较新帖子的 ID。在中继端,您执行 setTimeout(() => { this.props.relay.setVariables({timestamp: timestamp}); }, 60000)
在片段中类似:
const FooBar = Relay.createContainer(FooBarClass, {
initialVariables: {
timestamp: null
},
prepareVariables: vars => {
vars['timestampIsTruthy'] = !!vars['timestamp'];
return vars;
},
fragments: {
store: () => Relay.QL`
fragment on Query {
newerPosts(timestamp: $timestamp, first: 3) @include(if: $queryIsTruthy) {
totalCount
edges {
node {
id
}
}
}
}`,
},
});
关于javascript - 如何检查连接在中继中是否有新项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39919554/