我的RefetchContainer每次都发出带有相同参数的查询,但是流向refetchcontainer组件的道具不会更新。
这篇文章解释了为什么在使用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)
}
答案 0 :(得分:0)
@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);
}