[英]React-apollo update not reloading after mutation if I transform data before the render()
I have wrapped for both Query and Mutations so I can globally handle the repeat actions that need to happen with each Query, Mutation
. 我已经包装了Query和Mutations,所以我可以全局处理每个
Query, Mutation
需要发生的重复操作。 In the query I transform the data so I don't need to worry about all the nodes, edges, etc
在查询中我转换数据,所以我不需要担心所有的
nodes, edges, etc
I am using react-adopt
to wrap all my query
and mutations
components into one render prop back on the view layer. 我正在使用
react-adopt
将我的所有query
和mutations
组件包装回视图层上的一个渲染道具。
<ApolloQuery>
export const ApolloQuery = ({
query: query,
render,
}) => {
return (
<Query query={query}>
{({ data }) => {
return (
<Fragment>
render(data)
</Fragment>
)
}}
</Query>
)
}
export default externalProps => {
return (
<QueryContainer {...externalProps}>
{({ someQueryData, aMutation }) => { //react-adopt render props
const { nestedData } = new apolloClass(someQueryData).start()
return (
<Grid container spacing={16}>
{nestedData.map((ticket, index) => (
{...Mutation button in here}
))}
</Grid>
)
}}
</QueryContainer>
)
}
<ApolloQuery>
<Query query={query}>
{({ data }) => {
const transformedData = new apolloClass(data).start() //move transform into render
return (
<Fragment>
render(transformedData)
</Fragment>
)
}}
</Query>
export default externalProps => {
return (
<QueryContainer {...externalProps}>
{({ someQueryData: { nestedData }, aMutation }) => {
return (
<Grid container spacing={16}>
{nestedData.map((ticket, index) => (
{...Mutation button in here}
))}
</Grid>
)
}}
</QueryContainer>
)
}
So now, the page will not update after a mutation if I move the apolloClass
to transform before the render of the query
所以现在,如果我在
query
呈现之前移动apolloClass
进行转换,页面将不会在突变后更新
您很可能需要在突变选项中设置refetchQueries
或awaitRefetchQueries
以强制Apollo更新这些查询,从而触发重新渲染。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.