【问题标题】:Search with Relay doesn't include new results due to local cache由于本地缓存,使用 Relay 搜索不包含新结果
【发布时间】:2016-05-29 07:53:44
【问题描述】:

我已经在 React 和 Relay 中实现了一个搜索即输入的组件。与search functionality using relay的设置大致相同

它按预期工作,但有一个例外。当我重新键入已在客户端执行的搜索时,来自服务器的新结果永远不会出现。在这种情况下,我看起来 Relay 总是会进入本地缓存。

例如,假设我搜索了“foo”但没有找到任何结果。现在,几秒钟后,网站上的另一个用户创建了这个“foo”,但是 Relay 永远不会查询服务器,因为对“foo”搜索的缓存响应是一个空结果。

是否有适合这种情况的模式或最佳实践?

查询如下。我调用 this.props.relay.setVariables 来执行搜索:

initialVariables: {
    search: '',
    hasSearch: false
},
fragments: {
    me: () => Relay.QL`
        fragment on Viewer {
            relationSearch(search: $search) @include(if: $hasSearch) {
                ... on User {
                    username
                }
            }
        }
    `
}

【问题讨论】:

    标签: relayjs


    【解决方案1】:

    答案似乎是将 this.props.relay.forceFetch 与搜索变量一起使用。

    https://facebook.github.io/relay/docs/api-reference-relay-container.html#forcefetch

    如果这不是最佳做法,请有人纠正我。

    【讨论】:

    猜你喜欢
    • 2017-02-08
    • 1970-01-01
    • 1970-01-01
    • 2022-01-24
    • 2012-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多