Reactjs 使用react js在Apollo客户端中更改道具时未调用查询

Reactjs 使用react js在Apollo客户端中更改道具时未调用查询,reactjs,apollo,react-apollo,apollo-client,Reactjs,Apollo,React Apollo,Apollo Client,我需要在redux商店中更新道具时调用查询。但事实并非如此,在加载组件时只调用一次查询 我的代码是这样的-- const sampleData = compose(graphql(ITEMS_BY_CATEGORY, {name:"itemByCategory", options: (props) => ({variables: {_id:props.user._id,searchstring:"", start:0,limit:10, itemype:"created",catego

我需要在redux商店中更新道具时调用查询。但事实并非如此,在加载组件时只调用一次查询

我的代码是这样的--

  const sampleData = compose(graphql(ITEMS_BY_CATEGORY, {name:"itemByCategory", options: (props) => ({variables: {_id:props.user._id,searchstring:"", start:0,limit:10, itemype:"created",categoryid:props.categoryid}})}))(samplePage)

export default connect(
  (state) => ({user: state.user.user,categoryid: state.item.categoryid}),
  {}
)(sampleData);

我在道具更新后尝试了重蚀刻方法。比如-this.props.data.refetch()。但是它也不起作用。

添加
组件willreceiveprops()
并在那里调用查询。只要组件收到新道具,它就会运行。如果需要使用查询结果重新运行
render
函数,则可能需要调用
forceUpdate()

componentWillReceiveProps(nextProps) {
       const localThis = this;  
       this.client.query({
            query: MY_QUERY,
            variables: {myVar: theVar},
        }).then((result) => {
            localThis.setState({myStateVar: result.data.relevantData});
            localThis.forceUpdate();
        });
  }