Relay RefetchContainer 不更新 props

Relay RefetchContainer does not update props

我的 RefetchContainer 每次都使用相同的参数发出查询,但流向 refetchcontainer 组件的 props 没有更新。

此 post 解释了为什么在使用 RefetchContainers 时需要为您的片段使用变量 https://github.com/facebook/relay/issues/2244

但是我们每次调用refetch()时是否需要传递不同值的变量? 我怎样才能将新值添加到我的道具中?

这是我的 createRefetchContainer:

export default createRefetchContainer(
  DashboardRefetchContainer,
  {
    dashboardData: graphql`
      fragment DashboardRefetchContainer_dashboardData on Query @argumentDefinitions(
        idFund: {type: "String!"},
      )
      {
        ...DashboardTopMetrics_lastIntraDay
        ...DashboardTopMetrics_last12Month
        specsFundByIdFund(idFund: $idFund) {
          lastOne: fundsByIdFund(orderBy: [CREATED_AT_DESC] first:1) {
            nodes {
              ...Risk_expo
              ...Risk_vars
              betaOneYear
              drawdown
              exposureNet
              cash
              turnover
              benchmark
              volatility1Y
              navY
              nbOrders
            }
          }
        }
        specsFundByIdFund(idFund: $idFund) {
          ...Risk_tresh
        }
      }
    `,
    dashboardGraphData: graphql`
    fragment DashboardRefetchContainer_dashboardGraphData on Query @argumentDefinitions(
      idFund: {type: "String!"},
      fundCond: {type: "FundCondition!"},
    ){
      // more items...
      allFunds(first:7 orderBy: [CREATED_AT_DESC] condition: $fundCond) {
        ...LineFragCount_item
        ...LineFragPerc_item
        ...LineFragWatch_item
      }
      todayAssetAllPortfolio: todayAssetAllPortfolio(idFund: $idFund) {
        nodes {
          name
          priceEur
          expoEur
          valueEur
          asset {
            id
            position
            currency
            perc
            underlyingByUnderlying {
              tickerBbg
              perfDay
              perfWtd
              perfYtd
            }
          }
        }
      }
    }
    `
  },
  graphql`
    query DashboardRefetchContainerRefetchQuery($idFund: String!, $fundCond: FundCondition!) {
      ...DashboardRefetchContainer_dashboardData @arguments(idFund: $idFund)
      ...DashboardRefetchContainer_dashboardGraphData @arguments(idFund: $idFund, fundCond: $fundCond)
    }
  `
)

这里是 QueryRenderer graphql 查询:

  query DashboardMainChartsQuery($idFund: String!, $fundCond: FundCondition!) {
    ...DashboardRefetchContainer_dashboardData @arguments(idFund: $idFund)
    ...DashboardRefetchContainer_dashboardGraphData @arguments(idFund: $idFund, fundCond: $fundCond)
  }

@Louis,你必须传递一个 refetchVariables 才能重新获取。例如,如果你有一个 loadMore 函数,你可以有这样的东西:

  _loadMore() {
  // Increments the number of stories being rendered by 10.
  const refetchVariables = fragmentVariables => ({
    first: fragmentVariables.count + 10,
  });
  this.props.relay.refetch(refetchVariables);
}